On 30 Jun 2015, at 7:13 am, Deivy Petrescu <email@hidden> wrote:
Try this:
tell application "Finder" display dialog "Hello" say "Au revoir" end tell
It runs fine in spite the fact that say and display dialog are SA commands.
This is from the 10.6 AS Release Notes:
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.
Which is all very good, but doesn't tell us which are which, apart from 'display dialog'.
However, this < https://developer.apple.com/library/mac/technotes/tn1164/_index.html> tells us more, and you can look inside the Standard Additions Info.plist and see which have a Context of Process, which means they are good for use inside a tell block. That list includes the clipboard commands, path to, path to resource, all the commands that show dialogs, and localized string. As I read the tech note, that means the rest will be redirected.
And the 10.9 Release Notes say:
In scripts that use use scripting additions , AppleScript can optimize Apple event sending for some scripting addition commands, automatically eliminating the double-send described in Scripting Addition Security. Currently, it can perform this optimization for any scripting addition command with a Context value of Any in its Info.plist definition: for Standard Additions, this covers ASCII character , ASCII number , offset , random number , and round . This optimization is expected to cover more cases in the future; for best performance, make sure that your scripting addition has the strictest context possible.
As far as I can see, there's been no change in Context values for the commands in 10.10.
Nonetheless, apart from the bullet points above, there's no reason to think any commands won't work when used inside tell blocks. The notes suggest it's really a performance issue because of the redirection. That said, it seems like good practice.
Back to POSIX file: it returns exactly the same thing as using "as «class furl»", which seems to work fine inside a Finder tell block. Apart from perhaps being harder to type, it might be a better choice. |