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: 11193
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: 11193
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: 11193
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: 55
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: 11193
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: 55
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: 11193
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: 55
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: 11193
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Re: AppleScript error in preview Wed Jun 05, 2019 11:27 pm • by jfisher
I only get a chance to work on this every once in a while but am still having trouble getting this to work. I have tried pulling out the filename from theFile passed into the script to simplify it for myself and get all the expected behaviour when I run the file inside AppleScript. However, I still get the error Error executing AppleScript /Users/jfisher/SynologyDrive/#Hazel/Library/Genre/Apple.scpt: (null). when run inside Hazel (handler uncommented / manual path definition commented out).

It confuses me because the code from my pervious post above used to work and all of a sudden didn't even with the redundant passing in of the file name as mentioned.

Currently hazel is not passing any input attributes into the script.

Code: Select all
on hazelProcessFile(theFile, inputAttributes)
   --set theFile to quoted form of POSIX path of (choose file with prompt "Please choose a file:" default location (path to desktop)) --as string
   
   set filePath to (theFile as alias)
   
   set AppleScript's text item delimiters to "/"
   set theTextItems to text items of filePath
   set AppleScript's text item delimiters to {""}
   
   set fileName to last item of theTextItems
   
   --set Genre to name of text file
   set Genre to "Apple" as text
   
   -- set textPath
   set textPath to "Users:jfisher:SynologyDrive:#Hazel:Library:Genre:" & Genre & ".txt"
   
   -- set list 'matchFile' to paragraphs of text file from textPath
   set matchFile to paragraphs of (read alias textPath)
   
   try
      repeat with phrase in matchFile
         if phrase is in fileName then
            set answer to true
            exit repeat
            --else
            --set answer to false
            --exit repeat
         end if
      end repeat
   on error
      set answer to false
   end try
   return {hazelPassesScript:answer, hazelOutputAttributes:{Genre}}
   
end hazelProcessFile


    2019-06-05 23:25:24.941 HazelHelper[353] DEBUG: Thread 0x600003f59700: Run worker for folder: /Users/jfisher/Downloads/New Library
    2019-06-05 23:25:24.972 hazelworker[3576] Running worker (v4.3.5) for folder with identifier: 16777221-8609824759.
    2019-06-05 23:25:24.973 hazelworker[3576] ###main load address: 0x103cb9000
    2019-06-05 23:25:24.973 hazelworker[3576] ###Noodle load address: 0x103dd8000
    2019-06-05 23:25:24.973 hazelworker[3576] ###CK load address: 0x103d9d000
    2019-06-05 23:25:24.981 hazelworker[3576] DEBUG: Program is licensed.
    2019-06-05 23:25:25.014 hazelworker[3576] DEBUG: Could not read Mail preferences.
    2019-06-05 23:25:25.021 hazelworker[3576] Processing folder New Library (forced)
    2019-06-05 23:25:25.021 hazelworker[3576] DEBUG: Pausing to wait for things to settle down.
    2019-06-05 23:25:27.026 hazelworker[3576] DEBUG: Processing directories: (
    "/Users/jfisher/Downloads/New Library"
    )
    2019-06-05 23:25:27.029 HazelHelper[353] DEBUG: Checking events for path /Users/jfisher/Downloads/New Library, folder New Library
    2019-06-05 23:25:27.029 hazelworker[3576] DEBUG: About to process directory /Users/jfisher/Downloads/New Library
    2019-06-05 23:25:27.030 hazelworker[3576] DEBUG: .DS_Store: File is hidden/invisible. Skipping.
    2019-06-05 23:25:27.066 hazelworker[3576][PREDICTION] DEBUG: Calculating fire time - predicate: typeObject isType: "public.folder" result: 0
    2019-06-05 23:25:27.066 hazelworker[3576][PREDICTION] DEBUG: Next fire time: 4000-12-31 19:00:00.000
    2019-06-05 23:25:27.066 hazelworker[3576][PREDICTION] DEBUG: Bail out: AND predicate
    2019-06-05 23:25:27.066 hazelworker[3576][PREDICTION] DEBUG: Predicted fire time for file: /Users/jfisher/Downloads/New Library/Apple.jpg and rule Delete Empty Folders: 4000-12-31 19:00:00.000 Should poll: 0
    2019-06-05 23:25:27.067 hazelworker[3576][PREDICTION] DEBUG: Calculating fire time - predicate: typeObject isType: "public.folder" result: 0
    2019-06-05 23:25:27.067 hazelworker[3576][PREDICTION] DEBUG: Next fire time: 4000-12-31 19:00:00.000
    2019-06-05 23:25:27.067 hazelworker[3576][PREDICTION] DEBUG: Bail out: AND predicate
    2019-06-05 23:25:27.067 hazelworker[3576][PREDICTION] DEBUG: Predicted fire time for file: /Users/jfisher/Downloads/New Library/Apple.jpg and rule Run Rule On Folder Contents: 4000-12-31 19:00:00.000 Should poll: 0
    2019-06-05 23:25:27.068 hazelworker[3576][PREDICTION] DEBUG: Calculating fire time - predicate: typeObject isType: "public.folder" result: 0
    2019-06-05 23:25:27.068 hazelworker[3576][PREDICTION] DEBUG: Next fire time: 4000-12-31 19:00:00.000
    2019-06-05 23:25:27.068 hazelworker[3576][PREDICTION] DEBUG: Calculating fire time - predicate: subfolderLevel ==[cd] 0 result: 1
    2019-06-05 23:25:27.068 hazelworker[3576][PREDICTION] DEBUG: Next fire time: 4000-12-31 19:00:00.000
    2019-06-05 23:25:27.106 hazelworker[3576] [Error] Error during rule evaluation: Received error while trying to evaluate rule Genre on file Apple.jpg
    2019-06-05 23:25:27.106 hazelworker[3576] Error while matching rule Genre against file /Users/jfisher/Downloads/New Library/Apple.jpg: Error executing AppleScript /Users/jfisher/SynologyDrive/#Hazel/Library/Genre/Apple.scpt: (null).
    2019-06-05 23:25:27.106 hazelworker[3576] DEBUG: Tapping error retry sequence
    2019-06-05 23:25:27.106 hazelworker[3576] ###main load address: 0x103cb9000
    2019-06-05 23:25:27.106 hazelworker[3576] ###Noodle load address: 0x103dd8000
    2019-06-05 23:25:27.106 hazelworker[3576] ###CK load address: 0x103d9d000
    2019-06-05 23:25:27.106 hazelworker[3576] (
    0 CoreFoundation 0x00007fff42d2ecfd __exceptionPreprocess + 256
    1 libobjc.A.dylib 0x00007fff6d3d4a17 objc_exception_throw + 48
    2 CoreFoundation 0x00007fff42d2eb2f +[NSException raise:format:] + 201
    3 hazelworker 0x0000000103cf4d51 hazelworker + 245073
    4 Foundation 0x00007fff44f0f4bd -[NSComparisonPredicate evaluateWithObject:substitutionVariables:] + 306
    5 hazelworker 0x0000000103d2eaa8 hazelworker + 481960
    6 hazelworker 0x0000000103d32cda hazelworker + 498906
    7 hazelworker 0x0000000103d32e9e hazelworker + 499358
    8 hazelworker 0x0000000103d31222 hazelworker + 492066
    9 hazelworker 0x0000000103d3d3fc hazelworker + 541692
    10 hazelworker 0x0000000103d31222 hazelworker + 492066
    11 hazelworker 0x0000000103d3d3fc hazelworker + 541692
    12 hazelworker 0x0000000103cfece3 hazelworker + 285923
    13 hazelworker 0x0000000103cc0b3f hazelworker + 31551
    14 hazelworker 0x0000000103cc34cb hazelworker + 42187
    15 hazelworker 0x0000000103cc57dd hazelworker + 51165
    16 libdyld.dylib 0x00007fff6eba23d5 start + 1
    17 ??? 0x0000000000000003 0x0 + 3
    )
    2019-06-05 23:25:27.107 hazelworker[3576] DEBUG: Writing out DB file for /Users/jfisher/Downloads/New Library to path: /Users/jfisher/Library/Application Support/Hazel/16777221-8609824759.hazeldb
    2019-06-05 23:25:27.108 hazelworker[3576] DEBUG: Directory /Users/jfisher/Downloads/New Library processed in 0.078361 seconds
    2019-06-05 23:25:27.108 HazelHelper[353] DEBUG: Checking events for path /Users/jfisher/Downloads/New Library, folder New Library
    2019-06-05 23:25:27.108 hazelworker[3576] Received abort event.
    2019-06-05 23:25:27.108 hazelworker[3576] DEBUG: Sending metrics to scheduler. Next scheduled run: 2019-06-05 23:55:27.106
    2019-06-05 23:25:27.109 HazelHelper[353] DEBUG: Received metrics for folder /Users/jfisher/Downloads/New Library: {
    directoryDepth = 18446744073709551615;
    requestedSchedulingTime = "2019-06-06 03:55:27 +0000";
    triggerPaths = "<ComNoodlesoft_NoodlePathSet: 0x600002a6fb40>\n";
    unavailablePaths = "{(\n)}";
    }
    2019-06-05 23:25:27.109 HazelHelper[353] DEBUG: Timer scheduled for folder /Users/jfisher/Downloads/New Library at 2019-06-06 03:55:27 +0000
    2019-06-05 23:25:27.110 hazelworker[3576] Done processing folder New Library
    2019-06-05 23:25:27.112 HazelHelper[353] DEBUG: Thread 0x600003f59700: Task removed: [3576]
jfisher
 
Posts: 55
Joined: Sat Feb 25, 2017 7:47 pm

Re: AppleScript error in preview Thu Jun 06, 2019 9:55 am • by Mr_Noodle
Is that a compiled script file? Have you tried using an embedded script instead?
Mr_Noodle
Site Admin
 
Posts: 11193
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Re: AppleScript error in preview Thu Jun 06, 2019 1:06 pm • by jfisher
That is the actual AppleScript file. I have also tried it as an embedded script with no luck. I was assuming I had something wrong with my syntax but have tried to make it as simple as I know how and get the correct results when I run it manually in AppleScript.
jfisher
 
Posts: 55
Joined: Sat Feb 25, 2017 7:47 pm

Next

Return to Support