On Jan 19, 2012, at 10:42 AM, I wrote: On Jan 18, 2012, at 2:56 PM, I wrote: The command ...
tell application "TextEdit" to open fileAlias
if it cannot open the file, perhaps because of permissions, should return an error (number and description) to the script. It does not report an error to the script, but posts a dialog to the manual user.
I've been experimenting with ways to validate the fileAlias before telling an application to open the file. Here's a script that seems to work ...
try set filePath to (fileAlias as text) -- if the next line errors, then filePath is in posix form -- if the next line does not error, then filePath is in colon form (fileAlias as text) as alias --> error = -43 on error errText number errNr set volName to "" set filePath to (filePath as text) set AppleScript's text item delimiters to {"/"} repeat with i from 1 to (count text items of filePath) if (text item i of filePath) is "Volumes" then set volName to (text item (i + 1) of filePath) exit repeat end if end repeat "The disk \"" & volName & "\" may not be mounted." display dialog the result buttons {"OK"} return end try
-- the file alias is valid, continue with script
There are some odd things happening in this script, however. The line (fileAlias as text) as alias cannot be written as two lines. If you do that, neither of the lines will error. And I haven't the slightest idea why the posix/colon path is there. It just is.
|