applescript error only for compiled scripts

the following script runs fine from the script editor.
set username to “user”
set pwd to “pass”
set file_ to “Macintosh HD:Applications:file”

try
tell application “Finder” to disk username
– if it makes it this far, a disk named username was detected.
on error
– a disk named username wasn’t found so let’s try to mount the iDisk.
try
mount volume (“afp://” & username & “:” & pwd & “@idisk.mac.com/” & username)
on error mountError
display dialog mountError
return – terminate execution of the rest of the script
end try
end try
tell application “Finder”
–wait until idisk mounts
repeat while not (exists disk “user”)
end repeat
try
duplicate file_ to folder “Public” of disk username with replacing
on error dupeError
display dialog dupeError
end try
end tell

But when the script is compiled as an applet, it fails with error -1344

“Could not read the file because of a scripting system (OSA) error”
any ideas?

Does it work if you change this:

duplicate file_ to folder "Public" of disk username with replacing

To this:

duplicate alias file_ to folder "Public" of disk username with replacing

– Rob

I’ve started getting the same problem. I’ve got a script to print up a list of JPEG files in excel, it works fine run from the script editor but am get the error -1344 message when it is run as an applet. the apple website gives no hints.

the frustrating thing is that i believe the applet ran fine the first time i ran it. it wasn’t until i tried to run a second (and beyond) time that it didn’t work. pasting text to new script and resaving doesn’t work.

this is the script (yes it is ugly, i’ll make it more efficient once i have a consistently working product for users, at this point i just want to make it work again):

tell application “Finder”
set processFolder to “path:to:folder” as alias
set fileList to list folder processFolder
set listtoPrint to {}
set listtoPrintRef to a reference to listtoPrint
repeat with i in fileList
set singleFile to (i as string)
if singleFile ends with “.jpg” then
copy singleFile to the end of listtoPrintRef
end if
end repeat
end tell

tell application “Microsoft Excel”
Activate
Create New Workbook
set Value of Cell “R1C1” to “File Name”
set Value of Cell “R1C2” to “Photographer”
set Value of Cell “R1C3” to “Shot”
Select Range “C2”
set ColumnWidth of Selection to 14
Select Range “C1”
set ColumnWidth of Selection to 20
set rowRef to 2
repeat with x in listtoPrint
set eachName to (x as string)
set cellPosition to “R” & rowRef & “C1” as string
set Value of Cell cellPosition to eachName
set rowRef to rowRef + 1
end repeat

set PrintTitleRows of PageSetup of ActiveSheet to ""
set PrintTitleColumns of PageSetup of ActiveSheet to ""
set PrintArea of PageSetup of ActiveSheet to ""
set LeftHeader of PageSetup of ActiveSheet to ""
set CenterHeader of PageSetup of ActiveSheet to ""
set RightHeader of PageSetup of ActiveSheet to ""
set LeftFooter of PageSetup of ActiveSheet to ""
set CenterFooter of PageSetup of ActiveSheet to ""
set RightFooter of PageSetup of ActiveSheet to ""
set LeftMargin of PageSetup of ActiveSheet to 54.0
set RightMargin of PageSetup of ActiveSheet to 54.0
set TopMargin of PageSetup of ActiveSheet to 72.0
set BottomMargin of PageSetup of ActiveSheet to 72.0
set HeaderMargin of PageSetup of ActiveSheet to 36.0
set FooterMargin of PageSetup of ActiveSheet to 36.0
set PrintHeadings of PageSetup of ActiveSheet to false
set PrintGridlines of PageSetup of ActiveSheet to true
set PrintQuality of PageSetup of ActiveSheet to -4
set CenterHorizontally of PageSetup of ActiveSheet to false
set CenterVertically of PageSetup of ActiveSheet to false
set Orientation of PageSetup of ActiveSheet to xlPortrait
set Draft of PageSetup of ActiveSheet to false
set FirstPageNumber of PageSetup of ActiveSheet to xlAutomatic
set Order of PageSetup of ActiveSheet to xlDownThenOver
set BlackAndWhite of PageSetup of ActiveSheet to false
set Zoom of PageSetup of ActiveSheet to 100
Print SelectedSheets of ActiveWindow Copies 1
Close ActiveWindow

end tell


which leads me to another question, too, actually. In excel v.X when using the “Close ActiveWindow saving No” script (which is what is recorded when i just close out a window withouot saving), i get a save dialog. if i use what i have above, i of course get a dialog asking if i want to save before closing. anyone know how to actually make excel to close docs without saving or getting a dialog?

thanks,

david

David,

It’s likely that the following line is picking up invisible files that cause Finder to barf but I don’t know why it would only cause problems when saved as an appication.

set fileList to list folder processFolder

– Rob

Rob,

changed to “without invisibles” but still get same problem. runs from editor, not as applet. may have to break script down and run each part in another script to see which part is causing the error.

thanks,

david

Even ‘without invisibles’ isn’t 100% effective. You might have better luck telling Finder to get the list of files (‘list folder’ is handled by the Standard Additions osax). If I run ‘list folder’ on any populated folder, it returns a “.DS_Store” file in the list.

– Rob

Rob,

thanks for all your help, tried file instead of list folder. but still having the same problem. i’m heading out in about five minutes to go to the local bookstore to get me a book on applescript because maybe i’m just not understanding what you are trying to steer me towards. in the script i wrote, both list folder and file give me the same printable list, neither one adds the .DS_Store file to the excel list. and i checked (with display dialogs) to make sure it was even reviewing that file in the array loop, and sure enough it was. so the script soesn’t seem to be hanging up on the invisible files. but then again, maybe the applet is. i’m not sure how to tease out the difference between how the applet runs and how the compiled script runs through script editor (and how they may view invisibles differently). maybe this is because of my basic ignorance of how applescript works overall. reading up on it may help me.

david

you’re never going to believe this. the applet is now working again, albeit as a different file. I copied each segment of my script (the non-working one) to a new script, the finder section first - ran fine; the excel section second - ran fine (obviously missing the file list array, but at least it ran, not giving me that intro -1344 error). then, in the same editor window that housed the correctly performing second half of the script, i pasted the first half, saved it as an applet and the applet ran with no error.

my two conclusions are:

  1. bug in applescript?
  2. i somehow inserted an invisible character somewhere in the script that the application didn’t like that got lost when i took the pieces apart and reassembled them in a new script but retained when i just copied everything all at once. although going back to the old script and erasing the space between the two halves didn’t do the trick.

hopefully this will help others having this problem

David, a while back I was experiencing some weirdness in the Script Editor app. I trashed the “~/Library/Preferences/com.apple.ScriptEditor2.plist” and relaunched the Script Editor and all my problems went away. I’m using Script Editor 2.0b v36, if you are using the earlier version of the Script Editor your preference (.plist) file may be named “com.apple.ScriptEditor.plist”. It’s worth a try.

Yeah, I rebooted my machine and now the applet works fine-even when compiiled as run only.

BTW, using the word ‘alias’ only led to a type mismatch error.