Scripting Addition Security
For security reasons, most scripting addition commands now return a “privilege violation” error when sent between application processes. In order to preserve compatibility with existing scripts, AppleScript redirects most of these commands to the current application, that is, the process running the script. If a script sends events to a remote computer via EPPC (“Remote Apple Events”), AppleScript may redirect them to the System Events process on the target machine. AppleScript Editor’s Event Log will show when this redirection happens: you will see the event sent first to the original target process, return an error, and then sent again, often to the current application.
Some scripting addition commands, such as display dialog
, must be handled within the target process to operate correctly, and may require authenticating as an administrator if any of the following are true:
The sender and target processes have different user or group owner ids.
The target process is “tainted” by privilege level changes. (See issetugid
(2) for full details.)
The target application is not scriptable. To be considered scriptable, an application must have a terminology dictionary or the Info.plist key NSAppleScriptEnabled set to true.
If the event can be successfully redirected to the current process, then it didn’t need to be sent to the target process in the first place. You can eliminate the unnecessary double-send by moving the scripting addition command outside of the tell
block, or by adding tell current application to
to the command. For example, this script makes a new folder on the desktop named with the current date, but does it in a way that requires current date
to be sent twice:
tell application "Finder" |
set folderName to date string of (current date) |
make new folder with properties {name:folderName} |
end tell |
To eliminate the double send, move the current date
outside of the tell
block:
set folderName to date string of (current date) |
tell application "Finder" |
make new folder with properties {name:folderName} |
end tell |
Or add an inner tell
applying to the addition command:
tell application "Finder" |
tell current application to set folderName to date string of (current date) |
make new folder with properties {name:folderName} |
end tell |
KOENIG Yvan (VALLAURIS, France) lundi 15 juillet 2013 20:17:01