Getting external Applescript error -1708

Get help. Get answers. Let others lend you a hand.

Moderator: Mr_Noodle

Getting external Applescript error -1708 Mon Dec 24, 2012 7:35 am • by haze_l_user
Hi,

I am trying to get an applescript to work, but I keep getting the following error.
2012-12-24 03:09:04.733 hazelworker[2533] AppleScript error: {
OSAScriptErrorNumberKey = "-1708"

The script works fine on its own (e.g. if I provide the input folder via prompt). But when I plug that into hazel, even a trimmed down script seems to fail. I was able to get a somewhat similar script to work with files as input from hazel. But with folders as input, I have been unable to get it to run.

Following is my (trimmed down) script. This seems to work fine if I switch it to embedded script form. Any suggestions on what I might be doing wrong?

Code: Select all
on hazelMatchFile(theFile)
   set theFolder to theFile
   try
      tell application "Finder"
         -- Iterate over every file within the folder
         set filesToProcess to every file of theFolder
         repeat with eachFile in filesToProcess
            -- my processing goes here (but the script fails even without this content)
         end repeat
      end tell
 
      return true      
   on error errorMessage
      log errorMessage
      return false
   end try
end hazelMatchFile


Does hazel pass folder aliases to the script via theFile?

Also, my preference would be to avoid the applescript altogether and just use hazel; however, I need to make sure that hazel operates on my files in a specific order (e.g. by name). As an example, if I have 100 files in a folder, I need hazel to operate on A.XYZ followed by B.XYZ, C.XYZ and so on. However, hazel seems to pick up the files in an arbitrary sequence. Is there a way to achieve a strict order through hazel?

Either of these approaches would get me going (i.e. getting the applescript to work or having hazel operate in a specific order on the files).

Thanks in advance
haze_l_user
 
Posts: 6
Joined: Sun Nov 11, 2012 10:48 am

Re: Getting external Applescript error -1708 Wed Dec 26, 2012 2:12 pm • by a_freyer
Perhaps your error is like this user's error. He found that an AppleScript error -1708 was fixed by saving the external script as an *.scpt file, in lieu of plaintext.
a_freyer
 
Posts: 631
Joined: Tue Sep 30, 2008 9:21 am
Location: Colorado

That error claims that there was no proper handler. Note that you do not include the handler if embedding the script. Also, are you using this script in a condition or action? If the latter, you have the wrong handler specified. I suggest reading the help again on this as it has templates showing the correct handlers to use in each case.
Mr_Noodle
Site Admin
 
Posts: 11865
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Thank you both! This is embarrassing (but I'm new to this whole scripting thing, so please bear with me) - as Mr.Noodle pointed out, I did not have the right handler. When I tried with files, I used the script in a condition and the match file handler worked. When I created the script for folders, I used the script in an action, but I did not read the action help to change the handler. It works fine now with the right handler! My apologies!

Would you suggest anything for my other question? i.e. is there a way to have hazel operate on files in a strict sequence?

Thank you very much!
haze_l_user
 
Posts: 6
Joined: Sun Nov 11, 2012 10:48 am

Re: Getting external Applescript error -1708 Fri Dec 28, 2012 12:41 pm • by a_freyer
Here's an embedded script that will process the first alphabetical file in a directory only. If you move the files after processing to another directory, your batch of files will be processed alphabetically:

Code: Select all
exit $(ls | sort -uidf | head -1 | grep -cv "$(basename $1)")


NOTE: I did not post this from a computer I can test with; this may require some tweaking.

Applied like this:

Code: Select all
if (all) of the following conditions are met for (the file or folder being matched)
     passes shell script embedded script
     ...

Do the following to the matched file or folder:
     ...
     Move to directory "Processed"
a_freyer
 
Posts: 631
Joined: Tue Sep 30, 2008 9:21 am
Location: Colorado

Awesome! Sounds like I will have to use some simple script at least to help Hazel along with strict ordering. No problem if it is not tested - I get the general concept and can experiment with this to fit my needs. This really helps as I would prefer to have as much logic in Hazel as possible (vs placing the logic within a script).

Thanks again (a lot!), and happy holidays!
haze_l_user
 
Posts: 6
Joined: Sun Nov 11, 2012 10:48 am


Return to Support