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

Applescripting Chrome email
Hello all, I need some guidance please. Since recent security changes at Microsoft. AppleMail and Outlook on my very old MacBook (El Capitan) can no longer send/recieve emails as authorisation cannot bind. Before I could automate email (hotmail account) sending with AppleScript. I now use a web mail page for Outlook via Chrome but having to send manually. Can I get some advice on how to control, with AppleScript, the attached webpage to: open a new email add recipient in the To field add a subject attach a file send email. Or is there another solution (apart from buying a newer Mac!). Thank you
2
1
251
Sep ’24
script stopped working after upgrade to Sequoia
Hello, I don't know much about AppleScript, but I found this script on a Raycast site that dismisses Notification Center notifications. It worked great on Sonoma but has stopped working in Sequoia. Here is the code: tell application "System Events" tell process "NotificationCenter" if not (window "Notification Center" exists) then return set alertGroups to groups of first UI element of first scroll area of first group of window "Notification Center" repeat with aGroup in alertGroups try perform (first action of aGroup whose name contains "Close" or name contains "Clear") on error errMsg log errMsg end try end repeat -- Show no message on success return "" end tell end tell When using this to attempt to dismiss notifications, it returns the following error: Can’t get scroll area 1 of group 1 of window "Notification Center" of process "NotificationCenter". Invalid index. (-1719) Please help me fix it so it will run in Sequoia! This script was super useful.
1
2
297
Sep ’24
WatchOS 11 - Shortcut with SSH script returns "Cannot send with an inactive account"
Hi everyone, I have a shortcut that works great on iOS and on MacOS but that for some reason, doesn't work on WatchOS. The shortcut contains only a "Run script over SSH" item, I've tested both with password and public Key, they work well on the other devices but in WatchOS they shortcut returns "Cannot send with an inactive account". Any idea of what the issue is? Regards, Ade
3
0
386
Sep ’24
Shortcut action that should return a file deletes the file instead
I have an app intent that returns a file from inside the Sandbox. With iOS 18 RC, the call to INFile results in the file being deleted, instead of the file being returned. intentResponse.file = INFile(fileURL: fileURL, filename: fileName, typeIdentifier: nil) This seems to happen if the file was created by an earlier Shortcut action that calls FileManager().copyItem(), but not for files created by other means. I haven't found a reference in the developer documentation about INFile resulting in the file being deleted. I can block FileManager() from deleting the file by setting its immutable attributes to true, but that prevents me from removing it later.
3
2
433
Sep ’24
Modifying AAC/M4A audio file metadata with Shortcuts on macOS
I want to use the Shortcuts app on macOS Monterey to modify M4A/AAC audio file metadata for files that I have ripped from CD to my local Music app library. How can I use a regular expression on track titles to replace text that matches a certain regex pattern? I have already written the regex, I just need help with the Shortcuts app. I've started my shortcut with a "Find Music" action connected to a "Repeat with Each" loop action. Within the loop, I use a "Get Details of Music" action to get the title, which is passed to a "Replace Text" action using my regex. I just don't know how to write the correct new title into the music file's title/name metadata field. I tried a "Rename File" action with type "iTunes media" to try to set the "Title" field, but the field wasn't updated either in the Music app or in the M4A/AAC file itself. I couldn't find any other actions that seemed like they might be able to modify the field. I'd prefer a solution that goes through the Music app / its APIs, rather than directly modifying the M4A on the file system, because the latter would force me to have the Music app scan for changed files after the files we're modified.
0
0
286
Sep ’24
AppIntent with flexible return types
To support AppIntent in our app, we plan to follow the same approach as the “Get Details of Reminders” Shortcut Action in the Reminders app, as recommended in this WWDC session (https://developer.apple.com/wwdc24/10176?time=166). The goal is to allow querying all properties of an entity—referred to as “Node” in our app—using a single, configurable intent. For instance, we want one intent that can query properties like “Title,” “Background Color,” and “Font Name” for a specific node. However, since the returned properties have varying data types, this setup requires flexible return types in the perform implementation of our “Get Details” intent. The challenge is that the AppIntent protocol mandates the use ReturnsValue one associated type as the result of perform. For example, we can use ReturnsValue<String> to retrieve the “Title” property, but this would restrict us from using ReturnsValue<Color> for the “Background Color” property. What’s the best approach for implementing an Intent where the return types vary based on the input parameters provided?
1
0
344
Sep ’24
My Final Cut Pro extension is not allowed assistive access
I’m building an app extension for Final Cut Pro. It includes a main app that doesn't perform any actions, an extension that handles the code execution, and an export app responsible for uploading the exported file. To assist the user, I’ve added an upload button that triggers an AppleScript. This script exports the current project and then uploads it. The AppleScript simply selects the share option and the appropriate share destination. However, the issue arises when I click the upload button: the app asks the user to grant Automation permission, allowing it to control Final Cut Pro and System Events. After granting this permission, the script proceeds to the AppleScript, but an error occurs, stating: System Events got an error: APP is not allowed assistive access. Is there a permission I'm missing?
0
1
273
Sep ’24
Add option to finder context menu
Hello! I want to add an option to the finder context menu. In particular the context menu that shows when you right click empty space inside a folder. Its not problem if I have to write some swift code. It must be possible, because Google drive or Dropbox also add options to that menu directly. I do not want to add a option to the Quick options, but just an option that right below the "New folder" option. Is this possible? And can someone point me in the right direction? Maybe some API from apple or something? Thanks!
1
0
296
Aug ’24
Moving file to a system folder
When making a custom System Settings panel, I want the project to automatically move the prefpane file to /Library/PreferencePanes/. With Run Script, the build fails because of denial to perform the operation. Sudo doesn't help, too. PREFPANE_SRC="${BUILT_PRODUCTS_DIR}/App.prefPane" PREFPANE_DST="$HOME/Library/PreferencePanes/" echo "PrefPane source path: $PREFPANE_SRC" echo "PrefPane destination path: $PREFPANE_DST" if [ -d "$PREFPANE_SRC" ]; then echo "Installing preference pane to ${PREFPANE_DST}" cp -R "${PREFPANE_SRC}" "${PREFPANE_DST}" else echo "Preference pane not found: ${PREFPANE_SRC}" exit 1 fi
8
0
526
Aug ’24
Applescript: window API handler crashing in split view
I've a simple Applescript script as following: tell application "Terminal" -- Get the current tab set currentTab to selected tab of first window -- Set the current tab's theme to Homebrew set currentTab's current settings to settings set "Homebrew" end tell which works as expected when Terminal is run as a "normal" window, but fails with the following error when in Split View terminal-color.scpt: execution error: Terminal got an error: AppleEvent handler failed. (-10000) Any way to work around this error?
3
0
374
Aug ’24
Manually call App Intent from main app target
I would like to call my App Intent directly from my main app target, in an effort to start a live activity in the background when I receive a silent push notification from the server. I have seen in one of the WWDC developer lounges on Slack that this should be possible. Here is how I tried doing it: (it was recommended like that in the lounge) let appIntent = LiveActivityRefreshIntent() Task { try await appIntent() } But I get a compiler error: Instance method 'callAsFunction(donate:)' requires the types '(some IntentResult).Value' and 'Never' be equivalent It's strange because as far as I can tell, I cannot declare my perform method as returning Never. Here is the signature and return value of my App Intent's perform method: func perform() async throws -> some IntentResult { LiveActivityController.shared.updateLiveActivities() return .result() } Is there still a way to call the app intent from my code? If so, how?
0
1
343
Aug ’24
[osascript] Command + a doesn't work in chooseFile
When running this script a file selection dialog opens and allows to select multiple files, but cannot select all files by command + a. Isn't this a bug? I use MacBook Air M2 + macOS Sonoma 14.6 (23G80). #!/usr/bin/osascript -l JavaScript const app = Application.currentApplication(); app.includeStandardAdditions = true; app.chooseFile({ multipleSelectionsAllowed: true, });
0
0
251
Aug ’24
Issue with Launching Applications via XQuartz on 2024 MacBook Air
Dear Apple Developers, I hope this message finds you well. I apologize for the interruption; I am not a developer, but a user of MacBook who has encountered a frustrating issue when launching applications via Xquartz on my 2024 MacBook Air. After reaching out to Apple Support without success, I am seeking assistance here. I am an academic researcher in structural biology. Recently, I upgraded from a 2017 MacBook Pro to a 2024 MacBook Air. Since the upgrade, I have been unable to properly launch application GUIs from our HPC using SSH and the module load command, a process that worked seamlessly on my 2017 MacBook Pro. While Xquartz launches and runs in the background automatically on the 2024 MacBook Air, just as it did on the 2017 MacBook Pro, the application GUIs I need do not display correctly. Specifically, PyMOL opens with a blank interface, preventing me from viewing structures, and Chimera shows an error message before quitting automatically. I have attached the error logs for your reference. The most significant difference between the 2017 MacBook Pro and the 2024 MacBook Air is the transition from an Intel to an M3 chip. I wonder if this could be the root of the problem? Any assistance in resolving this issue would be greatly appreciated. Thank you very much for your time and support. Yours sincerely, Lingting Li
0
0
257
Jul ’24
Trouble with AppleScript Permissions and ShazamKit Integration in macOS App
Hello fellow developers, I am developing a macOS app called "Playlist Plunderer 2," aimed at using AppleScript to control the Music app to play songs and employing ShazamKit to recognize these songs and update their metadata. Despite setting up the entitlements and plist files correctly, I'm encountering issues with gaining the necessary AppleScript permissions, and my app is not appearing under 'Automation' in System Preferences. Additionally, ShazamKit fails to match songs, consistently returning error 201. Here are the specifics of my setup and what I've tried so far: Xcode Version: 15.4, macOS 14.1.2 Entitlements Configured: Includes permissions for Apple events, audio input, and scripting targets for the Music app. Capabilities: ShazamKit and ScriptingBridge frameworks integrated, set to "Do Not Embed." Info.plist Adjustments: Added "Privacy - Microphone Usage Description." Scripting: Manual AppleScript commands outside of Xcode succeed, but the app's scripts do not trigger. Entitlements File: <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"> <plist version="1.0"> <dict> <key>com.apple.security.app-sandbox</key> <true/> <key>com.apple.security.automation.apple-events</key> <true/> <key>com.apple.security.device.audio-input</key> <true/> <key>com.apple.security.files.user-selected.read-only</key> <true/> <key>com.apple.security.scripting-targets</key> <dict> <key>com.apple.Music</key> <array> <string>com.apple.Music.playback</string> <string>com.apple.Music.library.read-write</string> </array> </dict> </dict> </plist> I am having issues controlling the music app (itunes) from the apple script within my xcode project. the objective of the app is to rewrite the metadata of songs inside a folder in my Music app, this folder is titled Playlist Plunderer. The way I intend for the app to function is, the app will play the songs in the playlist, and then it will use shazamkit to recognize the song thats playing, it will then copy the metadata results of that song to rewrite the metadata of the song in the music playlist. I am still in the beginning stages. and I am very new to xcode. I created a apple developer account, paid the $99 and it is active, and I added the identifier bundle to the account from my app. I am VERY new to xcode,(this is my first project) my development team is set ( Shane Vincent), and the app is set to automatically manage signing, under app sandbox. i have audio input checked, under hardened runtime/ resource access audio input is checked. in build settings the path to the info.plist file is correct, the info.plist contains Privacy - Microphone Usage Description that I added i think it was called NSMmicriphone or something, with a description that reads "This app needs to access the microphone to identify songs using ShazamKit." the app appears under System Preferences > Security & Privacy > Privacy > Microphone but not under System Preferences > Security & Privacy > Privacy > Automation it is being made on macOS 14.1.2 (23B92) and xcode Version 15.4 (15F31d) Under framework library, and embedded content, I have added two frameworks, Shazamkit.framework, and ScriptingBridge.framework, both set to do not embed Current Issue: AppleScript fails to authorize with the Music app, and ShazamKit errors suggest an issue with song matching. Has anyone faced similar challenges or can offer guidance on how to ensure AppleScript and ShazamKit function correctly within a sandboxed macOS app? Any insights into troubleshooting or configuring entitlements more effectively would be greatly appreciated. Thanks for your help!
3
0
478
Jul ’24
Version 15.4 (15F31d) Xcode NSAppleScript of Safari broken
All attempts to script Safari in Xcode using NSAppleScript returns the following message. error: { NSAppleScriptErrorAppName = Safari; NSAppleScriptErrorBriefMessage = "Application isn\U2019t running."; NSAppleScriptErrorMessage = "Safari got an error: Application isn\U2019t running."; NSAppleScriptErrorNumber = "-600"; NSAppleScriptErrorRange = "NSRange: {32, 3}"; } Latest script attempt: func getHTML() -&gt; String { let source = """ tell application "Safari" get URL of tab 1 of window 1 end tell """ //print(source) var a = "hello" var error: NSDictionary? if let scriptObject = NSAppleScript(source: source) { if let scriptResult = scriptObject.executeAndReturnError(&amp;error).stringValue { a = scriptResult print(scriptResult) } else if (error != nil) { print("error: ",error!) } } return a }
3
0
713
Jul ’24
iOS Shortcuts Error Codes/Status
I’ve two automations set. Send a notification when battery rises above 80% Set Always ON display off on apple watch (via Shortcuts Automation, everyday at 12 a) For these aforementioned shortcuts I get the following errors frequently, on my Lock Screen, Wha is INCExtensionErrorDomain error 1307 and Remote execution timed out error? And how can these errors be mitigated?
0
0
529
Jul ’24