Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Unknown cause for -10004 error

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:my veryown: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)

Posted on Apr 9, 2011 10:02 AM

Reply
Question marked as Best reply

Posted on Apr 9, 2011 10:52 AM

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).
2 replies
Question marked as Best reply

Apr 9, 2011 10:52 AM in response to Livin Easy

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).

Apr 9, 2011 3:15 PM in response to red_menace

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.

Unknown cause for -10004 error

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.