2 Replies Latest reply: Apr 9, 2011 3:15 PM by Livin Easy
Livin Easy Level 1 Level 1 (0 points)
The following Applescript functions to the extent it accomplishes each 'say' command.

But the Events and Replies pane shows it encountering a '-10004' error with each list item, "A privilege violation occurred."

After the error, the 'end tell' is executed, followed by a tell block that isn't in ScriptEditor.app which actually accomplishes the 'say' command. A typical unknown 'tell' block appears this way in the execution sequence:

tell application "Finder"
say "85"
--> error number -10004
end tell
tell current application
say "85"
end tell
tell application "Finder"
say "86"
--> error number -10004

… and so on.

This example simplifies a more useful Applescript which fails in the same way, but halts execution inside a 'try' block. Can someone tell me how to eliminate the -10004 error, so I can solve my other scripting problem?

==== Applescript that produces the -10004 error ====

set currentFolder to "My HD:Users:myveryown:Desktop:Testing folder"

set currentList to ""

set currentFile to ""



tell application "Finder" -- collect list of items in folder; ref: p. 137, Language Guide

set currentList to the name of every file of folder currentFolder

end tell

try
tell application "Finder"


repeat with n from 1 to the count of currentList


set currentFile to item n of currentList


say text 7 thru 8 of currentFile


end repeat

end tell


end try

MacBook Pro Core 2 Duo, late 2007 2.2 GHz, Mac OS X (10.6.7)
  • red_menace Level 6 Level 6 (14,905 points)
    Error -10004 is an Apple Event Privilege Error. From the 10.6 AppleScript Release Notes - "For security reasons, most scripting addition commands now return a “privilege violation” error when sent between application processes." The say command is from *Standard Additions* (a scripting addition), so it should either not be used in a Finder tell statement, or prefixed with a tell me or tell current application so that you are not targeting the Finder - for example
    tell application "Finder"
    tell me to say "85"
    end tell


    In your second example, the try statement is trapping the error, but you are not doing anything with it. You should only target a particular application with terminology it knows (as previously mentioned), or fine tune the statements that you want to use the error trapping with (in addition to actually doing something with the error).
  • Livin Easy Level 1 Level 1 (0 points)
    Thank you. I now know better, about the lack of 'say' among Finder commands.

    For my actual Applescript I will use your advice well. For assuring a text string is as intended, I might use a different technique instead of 'say' for debugging text manipulation. But the call to TextEdit or other 'speak text' application does OK for now.

    Thanks again. Problem solved.