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

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
330
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
432
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
370
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
372
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
382
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
614
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
385
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
4
1
1.6k
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
390
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
383
Oct ’23
Applescript to estimate driving times
I'm trying to automate making accurate alarms to help me estimate when I need to leave to be on time for meetings. To do this accurately, I want to access Apple Maps (or Google Maps services, or ...) to get an estimate of driving times given current driving conditions. So I'd like to query the maps service reasonably close to departure time. (If I get an estimate on Sunday evening at for an appoint on Monday at rush hour leaving from a different location, it's obviously going to be inaccurate.) Ideally, I'd like to directly access my Apple Calendar to get the appointments and their locations. But if that's too complicated, I'll just create a formatted text file or sqlite file or whatever with the information. I've considered doing this with Shortcuts, Automator, AppleScript, JXA, Hammerspoon, Python, etc. It seems that each technology has part of what I need, but not all. But I don't have deep knowledge of any of them. Perhaps someone can advise me on the most appropriate technology. Here are my impressions: Shortcuts: Has built in access to driving time estimates and Calendar events, but awkward and possibly too limited in terms of program logic. Automator: Is more capable than Shortcuts in some ways, less in others. AppleScript: I don't know. JXA: I prefer Javascript to AppleScript, but it seems hard to find good documentation. Python: I'm quite proficient in Python, but I don't know if I can access things like Calendar events. If not, I'm willing to keep a separate file manually. (I could perhaps create the Calendar events from this, except that some appointments are set up by my work.) Hammerspoon: I don't have any experience with it and don't know it's capabilities. Any advice appreciated.
2
0
569
Sep ’23
AppleScript: RemoveEmojisFromFilename
Hi, So I've been trying to set up this applescript which removes Emojis from filenames in my Download folder. Right now it's set up to work with a droplet, but for some reason I get an error message when running the script. This is my error message: Can’t get name of alias "Macintosh HD:Users::Downloads:Armandocolor IDREAM - Alone RMX BURNAxBOY ❤️❤️❤️❤️❤️❤️.mp3". This is my scriptcode: -- Prompt user to choose files set selectedFiles to choose file with prompt "Select files to remove emojis from:" with multiple selections allowed processFiles(selectedFiles) end run on open theFiles -- Called when files are dropped onto the droplet processFiles(theFiles) end open on processFiles(fileList) repeat with aFile in fileList set fileName to name of aFile set newName to removeEmojisFromText(fileName) -- Check if the filename changed if newName is not equal to fileName then set name of aFile to newName end if end repeat end processFiles on removeEmojisFromText(inputText) set outputText to "" repeat with i from 1 to count characters of inputText set thisChar to character i of inputText if (thisChar is not in {"", return, tab}) then try set outputText to outputText & thisChar end try end if end repeat return outputText end removeEmojisFromText Can someone help me out with this code? I'm very much a noob still at applescripting...
0
0
384
Sep ’23
Iterate Window in Specified Application
I get the error code: System Events got an error: Can't get application of "Application Name" during this line repeat with currentWindow in every window of application foregroundApp of this code on run tell application "System Events" set foregroundApps to displayed name of (every process whose background only is false) as list repeat with foregroundApp in foregroundApps set appName to foregroundApp as text if exists (window 1 of process appName) then repeat with currentWindow in every window of application foregroundApp end repeat end if end repeat end tell end run I'm guessing I'm missing something like set x to foregroundApp as y repeat with currentWindow in every window of application x How do I get the windows of the application foreground app?
0
0
510
Sep ’23
Using AppleScript, how to confirm a folder action is actually removed?
I'm writing AppleScript to make a new folder action and attach it to a specified folder. In case there's already a folder action attached to the folder before make new folder action is executed, I want to delete that folder action already exists. tell application "System Events" repeat with i from 1 to count of folder actions if (path of folder action i) as string is equal to "/Users/foo/MyFolder" then delete folder action i exit repeat end if end repeat make new folder action at end of folder actions with properties {name:"MyFolderAction", path:"/Users/foo/MyFolder"} end tell However, it is still often that when make new folder action is executed, an error occured saying that "There is already a folder action with this path: /Users/foo/MyFolder". Maybe it's because that when make new folder action is executed, the delete folder action has not completed yet. Adding a delay 1 before make new folder action makes the error occured less fruequently, but not disappeared. Is there any method to confirm that the folder action is really deleted before make new folder action is executed?
0
0
397
Sep ’23
Speeding Up Code
I'm made a script that iterates through all windows and restores minimized windows. However, the script is quite slow. I'm wondering how to speed it up. I believe part of why the code is so slow is that it's looking at every process instead of every foreground process. Is it possible to do something like "repeat with p in every foreground process" or speed up this script through other means? on run {input, parameters} set windowNames to {} tell application "System Events" repeat with p in every process repeat with w in every window of p if value of attribute "AXMinimized" of w is true then set value of attribute "AXMinimized" of w to false end if end repeat end repeat end tell end run
2
0
509
Aug ’23
Iterate Window instead of Mass Operation
I'm trying to modify this code to work iteratively: on run {input, parameters} tell application id "com.apple.systemevents" to set the value of attribute "AXMinimized" of every window of every process to false end run Something along the lines of : on run {input, parameters} foreach windows of every process tell application id "com.apple.systemevents" to set the value of attribute "AXMinimized" to false end run Is this possible?
2
0
529
Aug ’23
Automated Mouse Moving
I am attempting to automate the movement of my mouse fully through Apple software. I have tried a variety of things, and I am now on the Dev Forums because I've ran out of ideas. Some of the things I have attempted are: Full Keyboard Access, Mouse Keys, Accessibility Keyboard with Panel Editor actions. Please, feel free to share any advice you may have. My goal is to only move the mouse enough for the computer to know it is active. That could be one pixel. Mouse keys works, but I can't get it to automate, I still have to click "u" and "o" to move the mouse. Thanks for any advice y'all may have! Have a blessed day!
0
0
407
Aug ’23
Remove ‘Fwd: ’ from an forwarded email subject
All works well, except that 'Fwd:' in the subject line, which I'd like to remove when forwarding tell application "Mail" set theMessage to item 1 of (get selection) set forwardedMessage to forward theMessage without opening window tell forwardedMessage make new to recipient at end of to recipients with properties {address:"a@b.com"} set message signature of forwardedMessage to signature "Blank" of application "Mail" set stringLength to (count subject of forwardedMessage) set subject of forwardedMessage to (characters 0 thru stringLength) as string send end tell end tell
0
0
390
Aug ’23
AppleScript Language Guide. open for access. The parameter is not specified in the syntax.
Here is the help for the "open for access" command. In the Syntax - Parameters section, the first parameter is not specified, but immediately write something in parentheses. In the "write" command, it is done differently. https://developer.apple.com/library/archive/documentation/AppleScript/Conceptual/AppleScriptLangGuide/reference/ASLR_cmds.html#//apple_ref/doc/uid/TP40000983-CH216-SW31
1
0
425
Aug ’23