The AppleScript script below returns a -600 error (application not running) under STP Tahoe version 231 and macOS 26.1. It functioned flawlessly under previous STP versions under macOS 15.x and 14.x.
tell application "Safari Technology Preview"
tell front window
set _old_tab to current tab
set _new_tab to make new tab at after _old_tab
set current tab to _new_tab
end tell
end tell
The following version returns a syntax error.
Tell application "System Events"
Tell process "Safari Technology Preview"
tell front window
set _old_tab to current tab
set _new_tab to make new tab at after _old_tab
set current tab to _new_tab
end tell
end tell
end tell
How would these scripts need to be fixed for STP 231 for Tahoe?
AppleScript
RSS for tagAppleScript allows users to directly control scriptable Macintosh applications as well as parts of macOS itself.
Posts under AppleScript tag
33 Posts
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Activity
On macOS Tahoe 26 activating GUI apps from command-line often fails.
It launches the app but not brings to the foreground as expected.
For example, running the following commands in Terminal is expected to launch Pages and bring it to the foreground.
open /Applications/Pages.app
or
osascript -e `tell application "Pages" to activate`
Moreover, they sometimes not return in Terminal.
These commands worked as expected until macOS 15 but no more in macOS 26.
The tricky part is that this failure doesn't happen 100% of the time; it occurs randomly.
However, since multiple users of my app have reported the same symptoms, and I can reproduce it not only with my app but also with apps bundled to macOS, I don't believe this is an issue specific to my environment alone.
I’ve already filed this issue: FB21087054
Open version: https://github.com/1024jp/AppleFeedback/issues/87
However, I’d like to know if any workaround exists or my understanding is wrong, especially for case with osascript.
Here is the appleScript part of my script:
tell application "Finder"
activate
open application file "Messages.app" of folder "Applications" of folder "System" of startup disk
end tell
What I need is a step to send the message already inside the Mesage.app. The message is ready to send. I just would like a step that will act as "Return" to send the message.
Again I have already prepared message to send but just need a step to send the message. Is there a possible step to perform the" Return" command to iMessage?
How do I convert screen pixels to points?
I plan to use the points in the program to move the shape to the desired position.
Hello.
How to write this command correctly on a Macbook, in the script editor, so that I can click the "Run script" button and the script will give the result:
if there is no folder, then report that there is no folder,
if there is a folder, then report that the folder exists.
do shell script "test -d 'Users/user/Desktop/New folder'"
Now, if the folder exists, an empty string ("") is returned, if the folder does not exist, the script editor reports that an error has occurred.
In general, my task is to write a script that checks the existence of a folder.
AppleScript for the Music app no longer supports the current track event. Before macOS Tahoe, running the following script in Script Editor would return the current track information:
tell application "Music"
return name of current track
end tell
However, when I run this script on a device with macOS 26 Tahoe, I receive this error:
"Result: error "Music got an error: Can’t get name of current track." number -1728 from name of current track”
I've tested this extensively, and here are my findings:
Going to the “songs” tab and playing something from there makes everything work.
Playing any song directly will make it work with current track UNLESS this song is NOT in your Music library (either added through Apple Music or uploaded).
If you play a song not in your library, current track is not updated even if you clicked on it specifically.
Playing an album (in your library obviously) makes all the tracks within it appear in current track until autoplay takes over.
Any autoplayed track won’t appear in current track even if in your library (unless: see the last bulletpoint)
Music played through the “songs” tab all appear in current track even if autoplay kicks in. I assume this is because this tab is an iTunes legacy (visually and under the hood) and doesn’t use the modern autoplay. This tab also won’t play non-library songs unlike the “albums” tab which seems to use the correct autoplay and suffers the same symptoms as the “recently added”, “home”, “radio”, etc… tabs.
Is this a bug, or has Apple simply deprecated this functionality?
I need my application to copy some files, but using Finder. Now, I know all different methods and options to programmatically copy files using various APIs, but that's not the point here. I specifically need to use Finder for the purpose, so please, let's avoid eventual suggestions mentioning other ways to copy files.
My first thought was to use the most simple approach, execute an AppleScript script using NSUserAppleScriptTask, but that turned out not to be ideal. It works fine, unless there already are files with same names at the copying destination. In such case, either the script execution ends with an error, reporting already existing files at the destination, or the existing files can be simply overridden by adding with overwrite option to duplicate command in the script.
What I need is behaviour just like when Finder is used from the UI (drag'n'drop, copy/paste…); if there are existing files with same names at the destination, Finder should offer a "resolution panel", asking the user to "stop", "replace", "don't replace", "keep both" or "merge" (the latter in case of conflicting folders). So, I came to suspect that I could achieve such bahaviour by using Apple Events directly and passing kAEAlwaysInteract | kAECanSwitchLayer options to AESendMessage(). However, I can't figure out how to construct appropriate NSAppleEventDescriptor (nor old-style Carbon AppleEvent) objects and instruct Finder to copy files.
This is where I came so far, providing srcFiles are source files (to be copied) URLs and dstFolder destination folder (to be copied into) URL:
NSRunningApplication *finder = [[NSRunningApplication runningApplicationsWithBundleIdentifier:@"com.apple.finder"] firstObject];
if (!finder)
{
NSLog(@"Finder is not running.");
return;
}
NSAppleEventDescriptor *finderDescriptor = [NSAppleEventDescriptor descriptorWithBundleIdentifier:[finder bundleIdentifier]];
NSAppleEventDescriptor *dstDescriptor = [NSAppleEventDescriptor descriptorWithString:[dstFolder path]];
NSAppleEventDescriptor *srcDescriptor = [NSAppleEventDescriptor listDescriptor];
for (NSURL *url in srcFiles)
{
NSAppleEventDescriptor *fileDescriptor = [NSAppleEventDescriptor descriptorWithString:[url path]];
[srcDescriptor insertDescriptor:fileDescriptor atIndex:([srcDescriptor numberOfItems] + 1)];
}
NSAppleEventDescriptor *event = [NSAppleEventDescriptor appleEventWithEventClass:kAECoreSuite
eventID:kAEClone
targetDescriptor:finderDescriptor
returnID:kAutoGenerateReturnID
transactionID:kAnyTransactionID];
[event setParamDescriptor:srcDescriptor forKeyword:keyDirectObject];
[event setParamDescriptor:dstDescriptor forKeyword:keyAETarget];
NSError *error;
NSAppleEventDescriptor *result = [event sendEventWithOptions:(NSAppleEventSendAlwaysInteract | NSAppleEventSendCanSwitchLayer) timeout:10.0 error:&error];
The code above executes without any error. The final result descriptor is a NULL descriptor ([NSAppleEventDescriptor nullDescriptor]) and there's no error returned (by reference). However, nothing happens, Finder remains silent and the application doesn't make macOS/TCC prompt for a permission to "automate Finder".
I wonder if the approach above is correct and if I use correct parameters as arguments for all calling method/messages. I'm specially interested if passing keyAETarget is the right value in [event setParamDescriptor:dstDescriptor forKeyword:keyAETarget], since that one looks most suspicious to me. I'd really appreciate if anyone can help me with this.
I'd also like to point out that I tried the same approach outlined above with old-style Carbon AppleEvent API, using AECreateDesc(), AECreateAppleEvent(), AEPutParamDesc() and AESendMessage()… All API calls succeeded, returning noErr, but again, nothing happened, Finder remained silent and no macOS/TCC prompt for a permission to "automate Finder".
Any help is highly appreciated, thanks!
-- Dragan
I use NSUserAppleScriptTask in my app to call Apple Script method to send Apple Events to Finder and System Events.
The script has been deployed in the folder ~/Library/Application Scripts/{app bundle id}/
I have configured the com.apple.security.automation.apple-events in the .entitlements file, but how to configure com.apple.security.scripting-targets to meet the AppStore review requirements
The existing official documentation is too incomplete to be of much use. If anyone has had similar experience, could you please share?
Script attachment enables advanced users to create powerful workflows that start in your app. NSUserScriptTask lets you implement script attachment even if your app is sandboxed. This post explains how to set that up.
IMPORTANT Most sandboxed apps are sandboxed because they ship on the Mac App Store [1]. While I don’t work for App Review, and thus can’t make definitive statements on their behalf, I want to be clear that NSUserScriptTask is intended to be used to implement script attachment, not as a general-purpose sandbox bypass mechanism.
If you have questions or comments, please put them in a new thread. Place it in the Privacy & Security > General subtopic, and tag it with App Sandbox.
Share and Enjoy
—
Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"
[1] Most but not all. There are good reasons to sandbox your app even if you distribute it directly. See The Case for Sandboxing a Directly Distributed App.
Implementing Script Attachment in a Sandboxed App
Some apps support script attachment, that is, they allow a user to configure the app to run a script when a particular event occurs. For example:
A productivity app might let a user automate repetitive tasks by configuring a toolbar button to run a script.
A mail client might let a user add a script that processes incoming mail.
When adding script attachment to your app, consider whether your scripting mechanism is internal or external:
An internal script is one that only affects the state of the app.
A user script is one that operates as the user, that is, it can change the state of other apps or the system as a whole.
Supporting user scripts in a sandboxed app is a conundrum. The App Sandbox prevents your app from changing the state of other apps, but that’s exactly what your app needs to do to support user scripts.
NSUserScriptTask resolves this conundrum. Use it to run scripts that the user has placed in your app’s Script folder. Because these scripts were specifically installed by the user, their presence indicates user intent and the system runs them outside of your app’s sandbox.
Provide easy access to your app’s Script folder
Your application’s Scripts folder is hidden within ~/Library. To make it easier for the user to add scripts, add a button or menu item that uses NSWorkspace to show it in the Finder:
let scriptsDir = try FileManager.default.url(for: .applicationScriptsDirectory, in: .userDomainMask, appropriateFor: nil, create: true)
NSWorkspace.shared.activateFileViewerSelecting([scriptsDir])
Enumerate the available scripts
To show a list of scripts to the user, enumerate the Scripts folder:
let scriptsDir = try FileManager.default.url(for: .applicationScriptsDirectory, in: .userDomainMask, appropriateFor: nil, create: true)
let scriptURLs = try FileManager.default.contentsOfDirectory(at: scriptsDir, includingPropertiesForKeys: [.localizedNameKey])
let scriptNames = try scriptURLs.map { url in
return try url.resourceValues(forKeys: [.localizedNameKey]).localizedName!
}
This uses .localizedNameKey to get the name to display to the user. This takes care of various edge cases, for example, it removes the file name extension if it’s hidden.
Run a script
To run a script, instantiate an NSUserScriptTask object and call its execute() method:
let script = try NSUserScriptTask(url: url)
try await script.execute()
Run a script with arguments
NSUserScriptTask has three subclasses that support additional functionality depending on the type of the script.
Use the NSUserUnixTask subsclass to run a Unix script and:
Supply command-line arguments.
Connect pipes to stdin, stdout, and stderr.
Get the termination status.
Use the NSUserAppleScriptTask subclass to run an AppleScript, executing either the run handler or a custom Apple event.
Use the NSUserAutomatorTask subclass to run an Automator workflow, supplying an optional input.
To determine what type of script you have, try casting it to each of the subclasses:
let script: NSUserScriptTask = …
switch script {
case let script as NSUserUnixTask:
… use Unix-specific functionality …
case let script as NSUserAppleScriptTask:
… use AppleScript-specific functionality …
case let script as NSUserAutomatorTask:
… use Automatic-specific functionality …
default:
… use generic functionality …
}
I'm trying to set a boolean value to myVariable using the "Folder" property, but the Applescript editor keeps interpreting it as a class.
Here is a shorted code. this is part of a bigger code to identify files dropped into a folder and create a new folder which it renames based on the date of the file that is dropped into the folder. Unfortunately, it keeps making folders every time it makes a new folder. Resalting in continuous loop of folders being created and renamed to "2025".
The plan is to us an IF condition to prevent the creation of folders when a folder/s are dropped into my folder with my Folder Action.
property directory : "Catalina:Users:Username:Desktop:Folder:File.pdf
tell application "Finder"
set pathname to POSIX path of directory
set item_info to the info for directory
set myVariable to Folder of item_info
return myVariable
end tell
I noticed the following when I compile the script
The color of the "Folder" is blue. I believe this means it's a class. Normally when I call a property, the color turns pink. it does it correctly when I use "set the file_name to the "name" of this_file". I also tried declaring the "Folder" property in brackets "Folder". did not help
I noticed the following when I run the script:
It returns ---error number -10004 "A privilege violation occurred. When it runs the "info for" command.
I gave the Script Editor Full File access, Full Accessibility access and the FolderActionsDispatcher has full Finder access.
Can anyone point me in the right direction!
What is the cause of the privilege violation or how would I find what the cause is?
How do I force the Script Editor to get the "Folder" property of a folder?
I've developed a Mac app distributed through the App Store that uses NSAppleScript to control Spotify and Apple Music. I'm experiencing inconsistent behavior with automation permission prompts that's affecting user experience.
Expected Behavior:
When my app first attempts to send Apple Events to Spotify or Apple Music, macOS should display the automation permission prompt, and upon user approval, the app should appear in System Preferences > Security & Privacy > Privacy > Automation.
Actual Behavior:
Initial permission prompts work correctly when both apps are actively used after my app download. If a user hasn't launched Spotify/Apple Music for an extended period, the permission prompt fails to appear when they later open the music app. The music app doesn't appear in the Automation privacy pane too. Once this happens, permission prompts never trigger again for that app
Steps to Reproduce:
Fresh install of my app
Don't use Spotify for several days/weeks
Launch Spotify
Trigger Apple Events from my app to Spotify
No permission prompt appears, app doesn't show in Automation settings
If you're using Apple Music during this time it runs without any problems.
Troubleshooting Attempted:
Used tccutil reset AppleEvents [bundle-identifier] - no effect
Verified target apps are fully launched before sending Apple Events
Tried different AppleScript commands to trigger permissions
Problem occurs inconsistently across different Macs
Technical Details:
macOS 13+ support
Using standard NSAppleScript with simple commands like "tell application 'Spotify' to playpause"
App Store distribution (no private APIs)
Issue affects both Spotify and Apple Music but seems more prevalent with Apple Music
Questions:
Is there a reliable way to programmatically trigger the automation permission prompt?
Are there timing dependencies for when macOS decides to show permission prompts?
Could app priority/usage patterns affect permission prompt behavior?
I use MediaManager to run the functions and initialize it on AppDidFinishLaunching method and start monitoring there.
Any insights or workarounds would be greatly appreciated. This inconsistency is affecting user onboarding and app functionality.
We are unable to programmatically enable AppleScript automation for VoiceOver on macOS 15 (Sequoia)
In macOS 15, Apple moved the VoiceOver configuration from:
~/Library/Preferences/com.apple.VoiceOver4/default.plist
to a sandboxed path:
~/Library/Group Containers/group.com.apple.VoiceOver/Library/Preferences/com.apple.VoiceOver4/default.plist
Steps to Reproduce:
Use a macOS 15 (ARM64) machine (or GitHub Actions runner image with macOS 15 ARM).
Open VoiceOver:
open /System/Library/CoreServices/VoiceOver.app
Set the SCREnableAppleScript flag to true in the new sandboxed .plist:
plutil -replace SCREnableAppleScript -bool true ~/Library/Group\ Containers/group.com.apple.VoiceOver/Library/Preferences/com.apple.VoiceOver4/default.plist
Confirm csrutil status is either disabled or not enforced.
Attempt to control VoiceOver via AppleScript (e.g., using osascript voiceOverPerform.applescript).
Observe that the AppleScript command fails with no useful output (exit code 1), and VoiceOver does not respond to automation.
Topic:
Accessibility & Inclusion
SubTopic:
General
Tags:
macOS
Accessibility
App Sandbox
AppleScript
Hello Shortcuts community!
I want to obtain a list of my notes, and well, update them, delete them if needed, and so on. These are simple actions that I can already do.
For this, I saw that shortcuts was pretty simple, and I could get what I wanted and pipe it through the terminal. However, even though I'm a programmer, there's a lot that I'm missing since I cannot pipe anything to the terminal.
I made a simple shortcut to give me some text, and I could obtain it via -shortcuts run "Example" | cat-, which well, gave me the output but with a %.
aaa**%**
Now, I guess this works, the important thing is for me to obtain something from shortcuts so that I can configure simple things like obtaining a note, a mail, run some javascript in the browser and so on while obtaining some output via the terminal.
So, I configured something like this:
While I do get a dictionary (only in the shortcuts app, not in the terminal) like:
{ "Title": "Some title" }
And actually a list of them, I don't have them in an array that I would have for my command. And for some reason I've only been able to obtain either the name or the body.
Now, I put them into a text with get text from Repeated results, but I don't think I have a valid Dictionary (JSON) array that I can use, since the terminal doesn't obtain nothing.
So far I've tried:
echo $(shortcuts run "Find Notes")
echo $(shortcuts run "Find Notes" --output-type public.utf8-plain-text -o -)
shortcuts run "Find Notes" | xargs
I wonder what am I missing. I'm not creating the array of dictionaries like I'd like, nor outputting it.
On the other hand, I have some AppleScripts that work, however, given that I cannot find munch information about the support status of AppleScript, I though to update to Shortcuts which is obtaining updates, and then I'm trying to do this simple example on shortcuts.
Thanks for taking a look!
In the past it was relatively easy to download from the developer portal both the app signing and installer signing certs so that I could sign AppleScripts from Script Editor when exporting them and when building packages in Jamf Composer.
I went to set that up today and it seems things have changed in the last few years since I've had to set this up. I've been unable to sort this out and would love some help.
I'm looking for a tutorial on doing this that walks someone step-by-step through the process for obtaining the certs (yes, I have dev account) and setting them up in keychain and then making use of them.
Thanks!
I ran the following script while both VSCode and Windsurf were open.
tell application "System Events"
set electronProcesses to every application process whose name is "Electron"
set outputText to ""
repeat with p in electronProcesses
set outputText to outputText & "Process: " & name of p
set outputText to outputText & ", Displayed name: " & displayed name of p
set outputText to outputText & ", Frontmost: " & frontmost of p & "
"
end repeat
return outputText
end tell
The script incorrectly returned two Electron processes, where both were showing Windsurf as the displayed name. The output of the above script is:
Process: Electron, Displayed name: Windsurf, Frontmost: false
Process: Electron, Displayed name: Windsurf, Frontmost: false
Separately, both Windsurf and VSCode share the same process name (Electron) but have different displayed names. This issue appears to affect how the frontmost application is detected, when using the following script:
set frontApp to first application process whose frontmost is true
The frontApp is incorrectly returned when switching between VSCode and Windsurf.
I am creating scripts to automatically switch the wallpapers on my multiple displays. System Events exposes almost all of the options accessible in the Wallpapers pane of system settings, but not the option to "Show on all Spaces".
I want to add that option to the following script:
tell application "System Events"
set intervalSeconds to 900.0
set wpDir to POSIX file "/Path/to/Folder/"
set picture rotation of every desktop to 1
set random order of every desktop to true
set pictures folder of every desktop to wpDir
set change interval of every desktop to intervalSeconds
do shell script ("killall Dock")
end tell
Also, the foregoing script does not seem to successfully set the interval value, although it does not throw an error. Not sure why that does not work.
Any thoughts or insights would be welcome.
Thank you
Is VIP an object contained in the mail or contacts apps/objects?
Or is it just a property somewhere?
Or is it an independent object?
Where is the VIP object? Is it still managed in the mail app or is it just hidden because the design is changing at Apple?
The following AppleScript is failing:
tell application "Mail"
set theVIPs to VIPs
with the error:
error "Die Variable „VIPs“ ist nicht definiert." number -2753 from "VIPs" (The variable "VIPs" is not defined.".
In Mail.sdef documentation and in Contacts.sdef documentation I cannot find any documentation of VIP object or VIP property.
Topic:
App & System Services
SubTopic:
Automation & Scripting
Tags:
Contacts
AppleScript
Mail Extensions
When using NSScriptCommand, is there any way to create an NSAppleEventDescriptor from an NSDictionary with arbitrary keys without using keyASUserRecordFields?
Am I correct in thinking that this constant is deprecated? I ask because there is still active documentation using it.
Is there another way to return a record where the keys aren't known at compile-time?
Topic:
App & System Services
SubTopic:
Automation & Scripting
Tags:
Foundation
Frameworks
macOS
AppleScript
Hi all,
I'm developing a sandboxed Mac OS app that generates and compiles AppleScript files to automate tasks in Pages (and other iWork apps). The app creates an AppleScript file and writes it to the NSApplicationScriptsDirectory (i.e., ~/Library/Application Scripts/com.example.app), then compiles and executes it via NSUserAppleScriptTask.
On Mac OS Ventura, however, I get the following error in the console when trying to write the file:
[PagesModifier] Error creating or compiling the script: You are not allowed to save the file "PagesModifier_...applescript" in the folder "com.example.app"
Here are my current entitlements:
<?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.application-groups</key>
<array/>
<key>com.apple.security.automation.apple-events</key>
<array>
<string>com.apple.iWork.Pages</string>
<string>com.apple.iWork.Numbers</string>
<string>com.apple.iWork.Keynote</string>
</array>
<key>com.apple.security.files.user-selected.read-write</key>
<true/>
<key>com.apple.security.scripting-targets</key>
<dict>
<key>com.apple.iWork.Keynote</key>
<array>
<string>com.apple.iWork.Keynote</string>
</array>
<key>com.apple.iWork.Numbers</key>
<array>
<string>com.apple.iWork.Numbers</string>
</array>
<key>com.apple.iWork.Pages</key>
<array>
<string>com.apple.iWork.Pages</string>
</array>
</dict>
<key>com.apple.security.temporary-exception.apple-events</key>
<array>
<string>com.apple.iWork.Pages</string>
<string>com.apple.iWork.Numbers</string>
<string>com.apple.iWork.Keynote</string>
</array>
<key>com.apple.security.temporary-exception.files.home-relative-path.read-write</key>
<array>
<string>Library/Application Scripts/com.example.app</string>
</array>
</dict>
</plist>
I suspect the issue might be due to sandbox restrictions on dynamically creating or modifying the Application Scripts directory on Ventura. Has anyone experienced something similar or have any suggestions on how to work around this?
Thanks in advance for your help!
Topic:
App & System Services
SubTopic:
Automation & Scripting
Tags:
Entitlements
Scripting
AppleScript
App Sandbox
Hi, I want to open an email message with AppleScript. Everything is working correctly, but in the Mail app, instead of focusing on targetMessage, it highlights the email after the target message.
When I use:
tell targetMessage to open
the correct email opens in new window but the wrong email is highlighted in the Mail app list.
tell application "Mail"
activate
set targetAccount to missing value
repeat with anAccount in every account
if name of anAccount is "AccountName" then
set targetAccount to anAccount
exit repeat
end if
end repeat
if targetAccount is not missing value then
set targetBox to missing value
repeat with aBox in mailboxes of targetAccount
if name of aBox is "MailboxName" then
set targetBox to aBox
exit repeat
end if
end repeat
if targetBox is not missing value then
set targetMessage to missing value
set oneWeekAgo to (current date) - (7 * days)
set filteredMessages to (every message of targetBox whose date received ≥ oneWeekAgo)
repeat with aMessage in filteredMessages
try
if message id of aMessage is "MessageID" then
set targetMessage to aMessage
exit repeat
end if
end try
end repeat
if targetMessage is not missing value then
if (count of message viewers) > 0 then
set mailViewer to message viewer 1
else
set mailViewer to make new message viewer
end if
tell mailViewer
set selected mailboxes to {targetBox}
delay 0.2
set selected messages to {targetMessage}
end tell
return "Found"
else
return "Message Not found"
end if
else
return "Folder Not found"
end if
else
return "Account Not found"
end if
end tell
Why is this behavior happening?