AppleScript error in preview

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

Moderator: Mr_Noodle

AppleScript error in preview Sun Nov 11, 2018 2:47 pm • by Patrick
Hi,
I note in the lastest release notes it says "Fixed preview of Apple/JavaScript conditions not working because of Mojave privacy protections. Note that you must still accept the prompt to allow access when it appears". I'm still getting an AppleScript error in preview mode. I'm not getting a prompt either. Is there a setting somewhere that I need to tweak?
Thanks,
Patrick
Patrick
 
Posts: 12
Joined: Fri Mar 27, 2015 12:55 am

Re: AppleScript error in preview Mon Nov 12, 2018 12:46 pm • by Mr_Noodle
Check your "Security & Privacy" settings. In the Automation section, HazelHelper should be in that list. Make sure to check any apps which you need to access there.
Mr_Noodle
Site Admin
 
Posts: 7756
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Re: AppleScript error in preview Fri Nov 16, 2018 10:02 pm • by Patrick
Hi. I've checked "Security & Privacy". In the automation section, HazelHelper is listed along with four applications PDFpenPro.app, OmniFocus.app, System Events.app, Finder - all of which are ticked. However, I'm still getting an AppleScript error in preview mode. If I put the code in the rule as embedded code (less the fist and last line) rather than calling an script file then it doesn't give an error. Any other ideas?

Code: Select all
on hazelMatchFile(theFile, inputAttributes)
   set docDate to first item in inputAttributes
   if docDate is equal to missing value then
      if (count of inputAttributes) is equal to 1 then
         return {hazelPassesScript:false}
      else
         set docDate to second item in inputAttributes
         if docDate is equal to missing value then
            return {hazelPassesScript:false}
         end if
      end if
   end if
   if month of docDate is greater than 6 then
      return {hazelPassesScript:true, hazelOutputAttributes:{"" & (year of docDate) + 1 & "", docDate}}
   else if month of docDate is less than 7 then
      return {hazelPassesScript:true, hazelOutputAttributes:{"" & (year of docDate) & "", docDate}}
   else
      return {hazelPassesScript:false}
   end if
end hazelMatchFile
Patrick
 
Posts: 12
Joined: Fri Mar 27, 2015 12:55 am

Re: AppleScript error in preview Mon Nov 19, 2018 12:59 pm • by Mr_Noodle
Can you post the exact text of the error?
Mr_Noodle
Site Admin
 
Posts: 7756
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Re: AppleScript error in preview Fri Nov 23, 2018 8:02 pm • by Patrick
The exact message is:

Error executing AppleScript /Users/Patrick/Library/Scripts/Applications/Hazel/getFinYear.scpt: (null).

The file getFinYear.scpt has the code that I posted in my previous message.

Thanks,

Patrick
Patrick
 
Posts: 12
Joined: Fri Mar 27, 2015 12:55 am

Re: AppleScript error in preview Mon Nov 26, 2018 12:50 pm • by Mr_Noodle
Was the script saved as an application instead of a script? Try opening it in Script Editor and re-saving it as a script to make sure.
Mr_Noodle
Site Admin
 
Posts: 7756
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Re: AppleScript error in preview Thu Jan 17, 2019 12:30 am • by jfisher
I am getting this error as well where applescripts fail to run (null) even though they were working previously and nothing changed. Was something changed with an update?
Last edited by jfisher on Thu Jan 17, 2019 5:38 pm, edited 1 time in total.
jfisher
 
Posts: 30
Joined: Sat Feb 25, 2017 7:47 pm

Re: AppleScript error in preview Thu Jan 17, 2019 11:27 am • by Mr_Noodle
Not that I know of. Can you provide more details about the script?
Mr_Noodle
Site Admin
 
Posts: 7756
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Re: AppleScript error in preview Fri Jan 18, 2019 12:25 am • by jfisher
I am using a series of text files containing a word per line and reading those text files into an AppleScript to check if the file name that Hazel passed to it contains any of the words in the text file.

I am doing it this way because I am using those same text files across multiple rules to filter files that can pass the general criteria phase but are sorted differently if they do or do not contain a sub-criteria or a combination. It helps me keep track of it rather than having the same matching criteria populated in multiple rules and if I forget to update one a file is missed.

As I update the text files all the rules become more refined.

What I don't understand is that the exact script below works for another script file and the only difference is which text file it is referencing. All of these were working nicely and sorting hundreds of files and all of a sudden kind of stopped. I ran a move all to monitored folder action and tried running them through again and only a few files actually end up sorted where they should.

Code: Select all
on hazelMatchFile(theFile, inputAttributes)
   
   -- set fileName to first item of inputAttributes list
   set fileName to item 1 of inputAttributes
   
   -- set path to matchFile:
   set matchFile to paragraphs of (read alias "Users:XXXX:XXXX:#Hazel:Library:Genre:EXAMPLE.txt")
   
   -- iterate through the matchList, textstring by textstring:
   repeat with textString in matchFile
      if textString is in fileName then
         return true
      else
         return false
      end if
   end repeat
   
end hazelMatchFile
jfisher
 
Posts: 30
Joined: Sat Feb 25, 2017 7:47 pm

Re: AppleScript error in preview Fri Jan 18, 2019 11:14 am • by Mr_Noodle
Are you sending in the filename as an input attribute? "theFile" should point to the input file and if you didn't set up Hazel to redundantly send in the file as the input attribute then the script won't work.
Mr_Noodle
Site Admin
 
Posts: 7756
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Re: AppleScript error in preview Fri Jan 18, 2019 12:06 pm • by jfisher
I am sending hazel input attribute “name” and only name into the script in the GUI rule interface. I restarted my computer and a bunch of the files went through but I’m still getting a error processing AppleScript error “filepath” (null) on a few. I have copied a script that works, renamed it, pointed it the right text file and made sure it’s called up in the file and the correct input attribute is passed to it but still get the error.

I restarted my computer again, moved everything back to the monitored and a different set of files went through.
jfisher
 
Posts: 30
Joined: Sat Feb 25, 2017 7:47 pm

Re: AppleScript error in preview Mon Jan 21, 2019 11:49 am • by Mr_Noodle
It's a bad idea to use only the name. That makes an assumption about what the current folder is which can change. I suggest you stick with using the file path already passed in.
Mr_Noodle
Site Admin
 
Posts: 7756
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City


Return to Support