Automation & Scripting

RSS for tag

Learn about scripting languages and automation frameworks available on the platform to automate repetitive tasks.

Automation & Scripting Documentation

Post

Replies

Boosts

Views

Activity

Help with a script to automate data entry
I am trying to write a script that will perform an operation in Numbers document TEST on sheet GAMES (it’s a bunch of random number generations for a game show simulator) look at the output in cell B66 of that sheet, output it in cell B3 on another sheet called TRIALS2 then perform the operation again and output the new result on sheet TRIALS2 in cell B4 and so on for 2000 repeats. Here’s the script I have but I get an error message. The document is open and I have confirmed all the document and sheet names are correct. There is definitely something in cell B66 of Sheet GAMES in document TEST. What am I missing? tell application "Numbers" activate tell document "TEST" repeat 2000 times tell sheet "GAMES" set inputValue to value of cell "B66" end tell tell sheet "TRIALS2" set table1 to table 1 set outputColumn to column "B" set nextRow to (get cell (3 + (count of rows of table1)) of outputColumn) set value of nextRow to inputValue end tell end repeat end tell end tell Here is the error message: error "Numbers got an error: Can’t get cell "B67" of sheet "GAMES" of document "TEST"." number -1728 from cell "B67" of sheet "GAMES" of document "TEST"
2
0
566
Mar ’24
Apple script stopped working - "invalid index"
Hi there, I've created an Automator app running an Apple script to toggle a setting within the "systems preferences". I'm on German systems settings, so I hope you can make any sense out of the below... The intention is to toggle a setting within "Desktop & Dock" off and on again (i.e., just toggle the blue switch left and right in one go). I've attached screenshots to make clear what I mean. I've been running the following Apple Script (for only a few weeks so far), and it worked perfectly fine until just recently: on run {} repeat 2 times tell application "System Settings" to activate tell application "System Events" tell process "System Settings" click menu item "Schreibtisch & Dock" of menu "Darstellung" of menu bar 1 delay 2 tell window "Schreibtisch & Dock" click checkbox "Beim Programmwechsel Space auswählen, der geöffnete Fenster des Programms enthält" of group 9 of scroll area 1 of group 1 of group 2 of splitter group 1 of group 1 end tell end tell end tell end repeat end run Now, since a few days, it keeps throwing an error message as follows: "System Events" has received an error: "group 1 of window "Desktop & Dock" of process "System Settings"" cannot be read. Invalid index. I'm not sure whether I've made an update of the MacOS in the meantime or what the reason could be. As mentioned, I'm not using the script for too much time, only a few weeks so far (mid-February). My MacOS version: Sonoma 14.3.1 Macbook Pro 16" 2021 (Apple M1 Pro) Unfortunately, my research did not point me into the right direction, I couldn't find an answer as to what exactly I'd need to change. Would much appreciate if anyone can help me set the correct index, or how to otherwise correct the script. Thanks a lot! S.
0
0
548
Mar ’24
Failed to gather url on browser windows via osascript (Apple Script)
I've been using Apple Script below for gathering every title & url of opening tab from browser window. It's been works fine for a few years but it's failed recently (maybe in last two weeks). #!/usr/bin/env osascript -l JavaScript // url.js function run(arg) { arg = arg.toString() let browser = '' switch(arg) { case 'chrome': browser = 'Google Chrome' break; case 'edge': browser = "Microsoft Edge" break; default: browser = 'Google Chrome' break; } Application(browser).windows().forEach((window) => { console.log('\n\n') window.tabs().forEach((tab) => { const url = tab.url() const name = tab.name() console.log(`${name}\t${url}`) }) }) } It's been works like below (imagine that you open https://example.com on edge) $ url.js edge example.com https://example.com But I found it failed today. $ url.js edge execution error: Error: Error: Application isn't running. (-600) of course I'm make sure Edge browser up and running. Same error for Chrome. I keep my environments(os, browser etc) up-to-date but I don't know which updates affects here. Any thoughts or helps are welcome. Settings MacBook Pro M2 Sonoma 14.2.1 Edge 122 Chrome 122
0
0
506
Mar ’24
Copy all Photos and Videos in a folder created after a certain date to a new folder
Hello - I have a lot of photos and videos that end up in my downloads folder from amusement park photographers and rides. The problem is that when I go to download a recent trip the amusement park website downloads everything all over again, and creates a lot of folder and files in a random sequence. So I have to go through each folder and find the "new" files that I want to add to the Photos app. Could you please help me write a script that would search through the entire downloads folder, and copy all of the files that are of photo or video type, created on or after a specified date, into a new folder within the downloads folder? This is effectively just eliminating the subfolders that the website download process created. From there I would go to the newly created folder and sort by created date to obtain the new photos I want to add to the Photos app.
1
0
582
Feb ’24
Seeking Assistance with AppleScript for Apple Reminders to Increment Date Without Changing Time to Midnight
Hi Community, I'm in need of some assistance with an AppleScript that increments the due date of reminders in the Apple Reminders app by one day. The reminders are set with a due date but do not have a specific time associated with them; they are just set to occur at some point during the day. The challenge I'm facing is that when I use AppleScript to add one day to the due date, the script is setting the new due date with a time of midnight. Since the original reminders do not have a time (just a date), I want the script to increment the date without adding a time. Here is the script I'm currently using: set myList to list "My List" repeat with myReminder in reminders of myList if (due date of myReminder is not missing value) then set currentDueDate to due date of myReminder set newDueDate to currentDueDate + (1 * days) set due date of myReminder to newDueDate end if end repeat end tell I am looking for a way to preserve the 'date only' attribute of the reminder when adding a day, so it does not default to a time of 00:00. Does anyone have experience with this, or can anyone provide guidance on how to accomplish this? I haven't found a way to specify 'no time' or 'all-day' in AppleScript for the Reminders app. Any help or pointers would be greatly appreciated. Thank you in advance!
1
0
451
Feb ’24
App Automatically Deleted from Applications Folder - OSX
I made an application in Script Editor and it works as expected. But the app seems to be getting automatically deleted at random times. For example, I made it a few days ago, tested it successfully, then went back today to look for it and it was gone. Tested this multiple times. I bit more detail about my process: I wrote the app in Script editor, exported it as an Application with run-only checked and no code signing after manipulating a few things (.plist file, .icns file), I then remove extended attributes and code-sign using terminal. I have an Apple developer account that I use to code-sign: xattr -cr <path_to_app> codesign -s <my_developer_account> <path_to_app_bundle> then I copy the app into my Applications folder and test it successfully a day or more later, the app is gone (and I haven't even opened it again) Ventura 13.1, Mac Book Pro 2021
1
0
655
Feb ’24
AppleScript to Get Open TextEdit RTF or RTFD File Properties & Copy to Clipboard?
A TextEdit RTD or RTFD document will save various document properties that you access and edit by selecting: File > Show Properties > Is is possible to retrieve these properties on a currently open document via AppleScript and place them in the clipboard? I am interested in storing some text in the Comments and later being able to copy it to the clipboard without having to manually open the properties window, selecting the text and copying it.
1
0
480
Jan ’24
Applescript not triggered by mail rule
Hi!! I tried posting about my issue on the macscripter forum, but haven't receieved any love there so I thought I would try giving it a go here. I'm trying to help automate my wife's business which uses mac and am having difficulty getting an applescript to trigger by mail rule. I am not an apple guy and myself use linux, so maybe i am overlooking something basic that I need to enable? I gave the mail.app full disk access in the security panel. If I set a rule, like to move a message to another mail folder it executes without problems. However, I can't get any applescripts to run triggered by mail rule, even something very simple...like writing to the display or logging an event. I looked through the console and saw no error messages or any evidence even that the applescript tried to run. We are running the latest mac sonoma. I asked chatgpt for help trying to debug what was wrong but it ran out of suggestions for me as well. This problem is driving me crazy, I can't understand how a nice new mac computer I bought for my wife's business is failing at the most basic task... arrrgh. Any help greatly appreciated!!!
1
0
488
Jan ’24
Error in signing app from Automator
Hi, I have an app generated by using osacompile on an applescript file. The app works fine as expected. However, when I try to sign it, I get two errors as in the screen shot below: After some googling around, I deleted the _CodeSignature folder in the .app directory but still signing fails with the same error. So, I would like to know two things: Is it possible to sign .app files created using osacompile as in my case? If yes, what am I missing and how to resolve my situation. Thanks,
1
0
541
Jan ’24
How can I run scripts with Sandbox enabled for AppStore distribution ?
Hey! Im new here and currently learning iOS/macOs development (SwiftUI), so...take me easy :) I want to create a simple macOS app to let user set time until computer power off. I found an example with AppleScript and use it on my app, but I found that App won't run with Sandbox enabled, and to deploy app on AppStore it show me that Sandbox must be enabled. The script I want to use: 'tell application "System Events" to shut down' I found some examples that add script onAbsolute path, but after I do that, it won't let me to distribute the app, only export to run local. It is any way to make script running (no matter, if app ask for user permission/admin pass) ?
1
0
910
Jan ’24
Launchctl agent errors
I am trying to automate a backup terminal script to mirror some directories to my NAS. The terminal script is working fine, so I want to automate them. The recommended path uses the launchctl agent, which, from the description, should be what I need. However, I have been running into two errors and looking for answers. I am using a M1 Mac mini with 8GB of memory (for reference). First, I get an error 23, which means too many files are open. If I reboot the machine, this error goes away. But why am I getting this message? I can run the script manually without a problem, and the system is running fine. The machine does little, so it should have almost nothing open. The second error, once the 23 is cleared, is error 12, cannot allocate memory. The machine is an 8GB machine but is reporting 3GB free. Again, the script runs fine in the terminal. I suspect the problem is the agent, but I am unsure how to diagnose or resolve these issues. I do not want to reboot the machine to run the backup, and so is the agent running under some system constraints that are too limiting. Can I change those limits for the job and make the recommended process to automate work? Any suggestions would be appreciated.
2
0
567
Jan ’24
Run a python script as a quick action in finder on selected folder
Hi, not sure if this forum is the right place to ask, but it’s extremely difficult to search the web for answers about shortcuts.app (must be the name…). I’m learning python currently and I’m trying to automate recurring tasks on my Mac easily. I have a python script as a first test-case that works (It basically makes a bunch of named folders). I use Apples Shortcuts.app to execute the python-file with the shell-script action. I start this script in Finder from the Quick Actions menu. The script creates my folders, but not in the selected folder when executing it, but always in my users home folder /Users/markus/. I suspect I have to somehow tell the Shortcut to take the currently selected folder as a variable or something. I tried to read the help but I don’t find anything useful and don’t understand the options of the Shell-Script Action in Shortcuts.app. Any ideas how I can get this to work? Or does anyone have a link to a good forum to ask questions about Shortcuts.app and automation? Thanks! Regards Markus
5
1
2.5k
Nov ’23
Access of app to read and write - Administrator cannot change access
Hey, please take a look at this code and tell me why it does not want to save file. Script is giving me an error that I do not have access to file. Error suggest that I need to change the mail access to read and write. After I open mail app -> information, previously unlocking the lock, I cannot add access, cannot change it and Sonoma showing error that I cannot change setting since I do not have access. Mail app has full disc access, as well as script editor and terminal. set acc_name to "TEST" set sender_email to "andrew" set email_subject to "Test" set download_folder to (POSIX file "location") as string set python_script to "location2" using terms from application "Mail" tell application "Mail" if not it is running then activate repeat with aMessage in messages of mailbox "Alpha" of account acc_name set client_sender to sender of aMessage set client_subject to subject of aMessage set client_attachment to name of mail attachment of aMessage as rich text set attachment_file to mail attachment of aMessage if client_sender is sender_email and client_subject is email_subject then --set noti_text of subject of aMessage display notification (client_sender & " " & client_attachment) as rich text with title client_subject tell application "Finder" delete (every item of folder download_folder) end tell --set attachmentPath to open for access download_folder & client_attachment with write permission --close access attachmentPath 6 save attachment_file in download_folder end if end repeat end tell end using terms from I am starting to think that it might be system error, not script issue.
2
1
508
Oct ’23
Automator creation of file names in 3rd party exports
Firstly, I'm a novice in automator & applescript. I have however managed to create an automator workflow that falls over at the second iteration. What I am trying to do is the following: working in Sierra I have an old app (Discus) that has an export capability for graphics that reside in the app. It appears that Discus does not have either AppleScript or Automator built in. The workflow has the following steps: move cursor direction right one keystroke (working) / select export from the menu (working) / keystroke a unique file name for the export file (not working) / save to folder (working) / Loop x1000 (working). At the moment the workflow falls over the second time it attempts to name the export file. I cannot find a way to auto create a new name for each iteration. Consequently Discus hangs waiting for a decision on whether to overwrite the initial exported file or to create a new filename. It would be beneficial to create a new file names using sequential numbering. There is an action for doing this in the finder, however this does not work in the workflow as I presume the file saving action is taking place in Discus, not in the finder. Any ideas on how to overcome this, or evenif it's possible. It may be that Automator in Sierra is more limited in capability than in current Mac OS? Thanks
0
0
505
Oct ’23
Scripting Zoom App - A Work In Progress
I know that zoom.us is not technically scriptable with Applescript but I have gotten so tired of repeatedly doing the same things when I set up a Zoom session that I started trying to automate the process using System Events and tell process. I was surprised by how much I could automate but then ran into a couple of brick walls. If anyone else is interested in this I'd like to brainstorm on the forum to see how much is possible. Here's some scripting steps I have been playing with. Part of what I decided to do in order to simplify the data entry involved in scheduling a new meeting and sending an email to the client was to run everything from Filemaker. The variables shows as $theMonth, $theDay, etc are being set in FileMaker before the Perform Applescript step so this is not a viable Applescript. You could use three separate Applescript dialog boxes to get the name date and time. The key code 48 is a tab to move between fields on the zoom interface. Key code 76 is the enter key which will OK the automatic entries in the Calendar so that I can quit Calendar and get back to zoom. There seems to be no way to stop zoom from automatically posting a new session in the Calendar. tell application "zoom.us" to activate tell application "System Events" tell process "zoom.us" repeat until window "Schedule Meeting" exists click menu item "Schedule Meeting..." of menu "Zoom.us" of menu bar 1 delay 0.2 end repeat set topicField to text field 1 of "Schedule Meeting" keystroke "Whatever You Want It To Be"" key code 48 keystroke $theMonth as text key code 48 keystroke $theDay as text key code 48 keystroke $theYear as text key code 48 keystroke $theHour as text key code 48 keystroke $theMinute as text key code 48 keystroke $theMonth as text key code 48 keystroke $theDay as text key code 48 keystroke $theYear as text key code 48 keystroke ($theHour + 1) as text key code 48 keystroke $theMinute as text Delay 2 key code 36 key code 76 key code 76 end tell end tell tell application "Calendar" to quit tell application "zoom.us" to activate tell application "System Events" tell process "zoom.us" repeat until window "Schedule Meeting" exists click menu item "Schedule Meeting..." of menu "Zoom.us" of menu bar 1 delay 0.2 end repeat select button ?????? end tell end tell The zoom.us interface for Meetings has what appear to be buttons for each scheduled meeting. I am trying to figure out how to select the right button so that I can then copy the invitation to put in an email. Tabbing does not let me select the button. If anyone has any ideas, I'd love to hear them, and if my further experiments produce any results, I'll post them. Thanks
3
0
2.6k
May ’21
Constant "Your session has expired" (error 1100)
Trying to do a CLI build with XCode (using NativeScript).Was working fine a couple days ago. However, now I cannot get past this error when trying to build:DTDeviceKit: deviceType from 7c64d8a014fd573ca3623ef80b158e57e7aea7c5 was NULL2018-05-07 11:57:54.696 xcodebuild[14808:865317] DVTPortal: Service '&lt;DVTPortalViewDeveloperService: 0x7fe4e17686d0; action='viewDeveloper'&gt;' encountered an unexpected result code from the portal ('1100')2018-05-07 11:57:54.696 xcodebuild[14808:865317] DVTPortal: Error:Error Domain=DVTPortalServiceErrorDomain Code=1100 "Your session has expired. Please log in." UserInfo={payload=&lt;CFBasicHash 0x7fe4e242ed70 [0x7fff9115faf0]&gt;Whenever I open XCode and to go preferences-&gt;account, my team account already reports "Session has expired". I log in successfully, then close Xcode, then login again, and once again it says the "Session has expired".Enabled two factor authentication hasn't helped. I get the identical error from two separate machines (Mac Mini and MacBook Air). Using latest High Sierra OS and XCode.My developer accounts logs in fine to the developer portal on Apple's Developer site, iTunes connect, etc..
15
0
36k
May ’18