Page 2 of 2

Re: AppleScript error in preview

PostPosted: Fri Jun 07, 2019 10:02 am
by Mr_Noodle
If using it as an embedded script, you need to get rid of the hazelProcessFile handler. Check the chapter in the help as it goes into more detail.

Re: AppleScript error in preview

PostPosted: Fri Jun 07, 2019 12:04 pm
by jfisher
Yes I am aware I need to remove the handler and have done so and still receive the same error.

Re: AppleScript error in preview

PostPosted: Mon Jun 10, 2019 10:00 am
by Mr_Noodle
I suggest then printing/displaying a dialog at different points in the script to see where it is failing.

Re: AppleScript error in preview

PostPosted: Tue Jun 11, 2019 10:17 pm
by jfisher
I changed the handler to hazelmatchfile instead of hazelprocessfile (oversight on my part). I also changed the line [b] set thefile to filename as text [b] and the script runs externally and sorts the files properly but I still receive the same error processing AppleScript (null) error.

Re: AppleScript error in preview

PostPosted: Wed Jun 12, 2019 10:27 am
by Mr_Noodle
Did you try the print/dialog option I suggested to narrow down where the error is occurring?

Re: AppleScript error in preview

PostPosted: Wed Jul 10, 2019 11:17 pm
by jfisher
I am still having trouble with this and can't seem to figure it out.

I have created a brand new script with help from someone of MacScripter which works perfectly fine inside AppleScript. When inserting the code inside the on hazelMatchFile() handler and running it inside Hazel I still get an error in the rule status window or preview

Error executing AppleScript /Users/jfisher/SynologyDrive/#Hazel/Library/cType.scpt: (null).

When looking at the log I see

Error executing AppleScript /Users/jfisher/SynologyDrive/#Hazel/Library/cType.scpt: No user interaction allowed..

I have tried uninstalling and reinstalling Hazel as well.

Re: AppleScript error in preview

PostPosted: Thu Jul 11, 2019 10:05 am
by Mr_Noodle
Without seeing the script I can't say for sure, but my guess is that you are trying to bring up some user interface directly, instead of doing it through a GUI process. I suggest putting that code in a 'tell application "System Events" ... end tell' block.

Re: AppleScript error in preview

PostPosted: Thu Jul 11, 2019 11:26 am
by jfisher
This is the new code I have tried. I will look at your recommendation when I get another chance to work on this.

Code: Select all
On hazelmatchfile(theFile, inputAttributes)

set theFilePath to theFile as text

-- Remove file path
set AppleScript's text item delimiters to "/"
set fullName to last text item of theFilePath
set AppleScript's text item delimiters to {""}

-- Remove extension
set AppleScript's text item delimiters to "."
set fileName to first text item of fullName
set AppleScript's text item delimiters to {""}

   -- Get a list of Finder references to the text files, sorted by name.
   -- For the moment, I've assumed that the "Text files" folder only contains the relevant text files, not in subfolders, and numbered as described in the post #1.
   tell application "Finder" to set cList to (sort every file of folder "SynologyDrive:#Hazel:Library:Text Files:" of home by name)
   
   -- Work through each text file in turn.
   repeat with textFile in cList
       -- Coerce each Finder reference to alias, read the corresponding text file, and extract the paragraphs.
       set textFileAlias to textFile as alias
       set matchList to paragraphs of (read textFileAlias as «class utf8») -- Assuming the text in the file is encoded as UTF-8.
       
       -- Work through the paragraphs and see if any of them contain the file name.
       repeat with i from 1 to (count matchList)
           set phrase to item i of matchList
           -- If any do, return the hit immediately.

if (fileName contains phrase) then
   set textFilePath to textFileAlias as text
   set astid to AppleScript's text item delimiters
   set AppleScript's text item delimiters to ":"
   -- Extract the file name from the HFS path. We can assume that the path to a readable text file doesn't end with a colon.
   set cType to text item -1 of textFilePath
   -- Drop the name extension if there is one, bearing in mind that names can contain more than one dot.
   if (cType contains ".") then
       set AppleScript's text item delimiters to "."
       set cType to text 1 thru text item -2 of cType
   end if
   set AppleScript's text item delimiters to astid
   
   return {hazelPassesScript:true, hazelOutputAttributes:{cType}}
end if

           
       end repeat
   end repeat
   
   -- If no hits above, return a 'false' result.
   return {hazelPassesScript:false}
end hazelMatchFile

Re: AppleScript error in preview

PostPosted: Fri Jul 12, 2019 10:35 am
by Mr_Noodle
Can you post the full error? Usually there's a line number of some sort to identify where the error is happening.

Re: AppleScript error in preview

PostPosted: Tue Aug 06, 2019 10:06 pm
by jfisher
Sorry I was away for work and didn't have any time to work on this. I tried to simplify this so I could understand since cannot remember what my setup was from my previous post.

To try and simplify, I have hazel running a basic external AppleScript and returning "Status" to sort the file into a folder named 'Passed' if the file matches and "Failed' if it does not. The rule preview for any AppleScript I try to run regardless of whether it processes or not shows the error "Error executing AppleScript (null). The script below runs properly and I do not see an error in the log but I still get the preview error.

Code: Select all
on hazelMatchFile(theFile, inputAttributes)
   
   set filename to theFile as text
   set match to "Ford"
   set status to "Fail"
   
   if filename contains match then
      set status to "Pass"
      return {hazelPassesScript:true, hazelOutputAttributes:{status}}
   end if
   return {hazelPassesScript:true, hazelOutputAttributes:{status}}
   
end hazelMatchFile


2019-08-06 21:28:03.796 HazelHelper[379] DEBUG: Thread 0x6000026d1700: Run worker for folder: /Users/jfisher/Downloads/TEST
2019-08-06 21:28:03.845 hazelworker[1538] Running worker (v4.3.5) for folder with identifier: 16777220-8611679993.
2019-08-06 21:28:03.846 hazelworker[1538] ###main load address: 0x10cdac000
2019-08-06 21:28:03.846 hazelworker[1538] ###Noodle load address: 0x10ced0000
2019-08-06 21:28:03.846 hazelworker[1538] ###CK load address: 0x10ce95000
2019-08-06 21:28:03.853 hazelworker[1538] DEBUG: Program is licensed.
2019-08-06 21:28:03.889 hazelworker[1538] DEBUG: Could not read Mail preferences.
2019-08-06 21:28:03.897 hazelworker[1538] Processing folder TEST (forced)
2019-08-06 21:28:03.897 hazelworker[1538] DEBUG: Pausing to wait for things to settle down.
2019-08-06 21:28:05.897 hazelworker[1538] DEBUG: Processing directories: (
"/Users/jfisher/Downloads/TEST"
)
2019-08-06 21:28:05.899 HazelHelper[379] DEBUG: Checking events for path /Users/jfisher/Downloads/TEST, folder TEST
2019-08-06 21:28:05.899 hazelworker[1538] DEBUG: Received file event: {
date = "2019-08-07 01:28:03 +0000";
path = "<ComNoodlesoft_NoodlePathSet: 0x7fd19af19860>\n /Users/jfisher/Downloads/TEST : 18446744073709551615\n";
}
2019-08-06 21:28:05.900 hazelworker[1538] DEBUG: About to process directory /Users/jfisher/Downloads/TEST
2019-08-06 21:28:05.900 hazelworker[1538] DEBUG: .DS_Store: File is hidden/invisible. Skipping.
2019-08-06 21:28:05.937 hazelworker[1538][PREDICTION] DEBUG: Calculating fire time - predicate: typeObject isType: "public.folder" result: 1
2019-08-06 21:28:05.937 hazelworker[1538][PREDICTION] DEBUG: Next fire time: 4000-12-31 19:00:00.000
2019-08-06 21:28:05.938 hazelworker[1538][PREDICTION] DEBUG: Calculating fire time - predicate: subitemCount ==[cd] 0 result: 0
2019-08-06 21:28:05.938 hazelworker[1538][PREDICTION] DEBUG: Next fire time: 4000-12-31 19:00:00.000
2019-08-06 21:28:05.938 hazelworker[1538][PREDICTION] DEBUG: Bail out: AND predicate
2019-08-06 21:28:05.938 hazelworker[1538][PREDICTION] DEBUG: Predicted fire time for file: /Users/jfisher/Downloads/TEST/Pass and rule Delete Empty Folders: 4000-12-31 19:00:00.000 Should poll: 0
2019-08-06 21:28:05.939 hazelworker[1538][PREDICTION] DEBUG: Calculating fire time - predicate: typeObject isType: "public.folder" result: 1
2019-08-06 21:28:05.939 hazelworker[1538][PREDICTION] DEBUG: Next fire time: 4000-12-31 19:00:00.000
2019-08-06 21:28:05.939 hazelworker[1538][PREDICTION] DEBUG: Bail out: AND predicate
2019-08-06 21:28:05.939 hazelworker[1538][PREDICTION] DEBUG: Predicted fire time for file: /Users/jfisher/Downloads/TEST/Pass and rule New Rule: 4000-12-31 19:00:00.000 Should poll: 0
2019-08-06 21:28:05.940 hazelworker[1538] DEBUG: Pass: Did not match any rules.
2019-08-06 21:28:05.941 hazelworker[1538][PREDICTION] DEBUG: Calculating fire time - predicate: typeObject isType: "public.folder" result: 0
2019-08-06 21:28:05.941 hazelworker[1538][PREDICTION] DEBUG: Next fire time: 4000-12-31 19:00:00.000
2019-08-06 21:28:05.941 hazelworker[1538][PREDICTION] DEBUG: Bail out: AND predicate
2019-08-06 21:28:05.941 hazelworker[1538][PREDICTION] DEBUG: Predicted fire time for file: /Users/jfisher/Downloads/TEST/IMG_2580.jpeg and rule Delete Empty Folders: 4000-12-31 19:00:00.000 Should poll: 0
2019-08-06 21:28:05.942 hazelworker[1538][PREDICTION] DEBUG: Calculating fire time - predicate: typeObject isType: "public.folder" result: 0
2019-08-06 21:28:05.942 hazelworker[1538][PREDICTION] DEBUG: Next fire time: 4000-12-31 19:00:00.000
2019-08-06 21:28:05.982 hazelworker[1538][PREDICTION] DEBUG: Calculating fire time - predicate: appleScript passesAppleScript: /Users/jfisher/Desktop/TEST SCRIPT.scpt:(
)-(
"{hazelcustomtoken:Status:sc0:cap}"
) result: 0
2019-08-06 21:28:05.982 hazelworker[1538][PREDICTION] DEBUG: Next fire time: 4000-12-31 19:00:00.000
2019-08-06 21:28:05.982 hazelworker[1538][PREDICTION] DEBUG: Bail out: AND predicate
2019-08-06 21:28:05.982 hazelworker[1538][PREDICTION] DEBUG: Predicted fire time for file: /Users/jfisher/Downloads/TEST/IMG_2580.jpeg and rule New Rule: 4000-12-31 19:00:00.000 Should poll: 0
2019-08-06 21:28:05.982 hazelworker[1538] DEBUG: IMG_2580.jpeg: Did not match any rules.
2019-08-06 21:28:05.982 hazelworker[1538] DEBUG: Directory /Users/jfisher/Downloads/TEST processed in 0.082831 seconds
2019-08-06 21:28:05.983 HazelHelper[379] DEBUG: Checking events for path /Users/jfisher/Downloads/TEST, folder TEST
2019-08-06 21:28:05.983 hazelworker[1538] DEBUG: Sending metrics to scheduler. Next scheduled run: 4000-12-31 19:00:00.000
2019-08-06 21:28:05.984 HazelHelper[379] DEBUG: Received metrics for folder /Users/jfisher/Downloads/TEST: {
directoryDepth = 1;
requestedSchedulingTime = "4001-01-01 00:00:00 +0000";
triggerPaths = "<ComNoodlesoft_NoodlePathSet: 0x6000033917c0>\n";
unavailablePaths = "{(\n)}";
}
2019-08-06 21:28:05.984 HazelHelper[379] DEBUG: Timer scheduled for folder /Users/jfisher/Downloads/TEST at 4001-01-01 00:00:00 +0000
2019-08-06 21:28:05.984 hazelworker[1538] Done processing folder TEST
2019-08-06 21:28:05.987 HazelHelper[379] DEBUG: Thread 0x6000026d1700: Task removed: [1538]

Re: AppleScript error in preview

PostPosted: Wed Aug 07, 2019 10:04 am
by Mr_Noodle
I'm not seeing the AppleScript error in that log.

Re: AppleScript error in preview

PostPosted: Thu Feb 25, 2021 12:33 am
by jfisher
Hello,

I am back to receiving the same error "Error executing AppleScript - (null)" on a new project.

I have placed one image inside the folder to run the script but see this error and the file is not processed. The log and final AppleScript are below. I have tested the script in AppleScript Editor with no issues. I receive this error on any external AppleScript I try. to run.

2021-02-24 23:32:23.458 hazelworker[16139] Running worker (v5.0.5) for folder with identifier: 16777220-8639505854.
2021-02-24 23:32:23.460 hazelworker[16139] ###main load address: 0x10188d000
2021-02-24 23:32:23.460 hazelworker[16139] ###Hazel Core load address: 0x1018c4000
2021-02-24 23:32:23.460 hazelworker[16139] ###Noodle load address: 0x1019de000
2021-02-24 23:32:23.460 hazelworker[16139] ###CK load address: 0x101995000
2021-02-24 23:32:23.468 hazelworker[16139] DEBUG: Program is licensed.
2021-02-24 23:32:23.516 hazelworker[16139] Processing folder Exif Test (forced)
2021-02-24 23:32:23.516 hazelworker[16139] DEBUG: Pausing to wait for things to settle down.
2021-02-24 23:32:25.521 hazelworker[16139] DEBUG: Processing directories: (
"/Users/jfisher/Downloads/Exif Test"
)
2021-02-24 23:32:25.560 hazelworker[16139] DEBUG: About to process directory /Users/jfisher/Downloads/Exif Test
2021-02-24 23:32:25.561 hazelworker[16139] DEBUG: .DS_Store: File is hidden/invisible. Skipping.
2021-02-24 23:32:25.623 hazelworker[16139][PREDICTION] DEBUG: Calculating fire time - predicate: typeObject isType: "public.folder" result: 0
2021-02-24 23:32:25.623 hazelworker[16139][PREDICTION] DEBUG: Next fire time: 4000-12-31 19:00:00.000
2021-02-24 23:32:25.664 hazelworker[16139] [Error] Error during rule evaluation: Received error while trying to evaluate rule New Rule on file 051216RMAR2017 Zion National Park, Utah - Utah, USA.JPG
2021-02-24 23:32:25.664 hazelworker[16139] Error while matching rule New Rule against file /Users/jfisher/Downloads/Exif Test/051216RMAR2017 Zion National Park, Utah - Utah, USA.JPG: Error executing AppleScript /Users/jfisher/SynologyDrive/#Hazel/Exiftool/Exiftool GPS Script.scpt: (null).
2021-02-24 23:32:25.664 hazelworker[16139] DEBUG: Tapping error retry sequence
2021-02-24 23:32:25.664 hazelworker[16139] ###main load address: 0x10188d000
2021-02-24 23:32:25.664 hazelworker[16139] ###Hazel Core load address: 0x1018c4000
2021-02-24 23:32:25.664 hazelworker[16139] ###Noodle load address: 0x1019de000
2021-02-24 23:32:25.664 hazelworker[16139] ###CK load address: 0x101995000
2021-02-24 23:32:25.664 hazelworker[16139] (
0 CoreFoundation 0x00007fff206fa6af __exceptionPreprocess + 242
1 libobjc.A.dylib 0x00007fff204323c9 objc_exception_throw + 48
2 CoreFoundation 0x00007fff206fa513 +[NSException raise:format:] + 189
3 HazelCore 0x00000001018d1fd6 hasNSRecords + 10769
4 Foundation 0x00007fff214143ff -[NSComparisonPredicate evaluateWithObject:substitutionVariables:] + 303
5 HazelCore 0x000000010191a063 hazelKindFromUTI + 2994
6 HazelCore 0x000000010191e6d0 _isDateValue + 802
7 HazelCore 0x000000010191e88b _isDateValue + 1245
8 HazelCore 0x000000010191c640 hazelKindFromUTI + 12687
9 HazelCore 0x0000000101920812 _isDateValue + 9316
10 HazelCore 0x00000001018f5bf2 errorFromOSAScriptErrorDict + 88695
11 hazelworker 0x000000010189335c hazelworker + 25436
12 hazelworker 0x00000001018962eb hazelworker + 37611
13 hazelworker 0x00000001018986f9 hazelworker + 46841
14 libdyld.dylib 0x00007fff205a3621 start + 1
15 ??? 0x0000000000000003 0x0 + 3
)
2021-02-24 23:32:25.664 hazelworker[16139] DEBUG: Writing out DB file for /Users/jfisher/Downloads/Exif Test to path: /Users/jfisher/Library/Application Support/Hazel/16777220-8639505854.hazeldb
2021-02-24 23:32:25.670 hazelworker[16139] DEBUG: Directory /Users/jfisher/Downloads/Exif Test processed in 0.110445 seconds
2021-02-24 23:32:25.671 hazelworker[16139] Received abort event.
2021-02-24 23:32:25.671 hazelworker[16139] DEBUG: Sending metrics to scheduler. Next scheduled run: 2021-02-25 00:02:25.664
2021-02-24 23:32:25.671 hazelworker[16139] Done processing folder Exif Test


Code: Select all
use AppleScript version "2.5"
use framework "Foundation"
use scripting additions

property || : a reference to current application

on hazelProcessFile(theFile, inputAttributes)
   
   set ExifTool to "/usr/local/bin/exiftool"
   set ExifGPSLat to "-GPSLatitude"
   set ExifGPSLon to "-GPSLongitude"
   set ExifToolOption to "-keywords="
   
   set pathList to ""
   
   set TagTool to "/usr/local/bin/tag"
   set TagToolOption to "-s" -- The set operation reTrails all tags on the specified files with one or more new tags.
   set TagToolNOGPS to "NO GPS Information"
   
   try
      -- Manual
      --set pathList to quoted form of POSIX path of (choose file with prompt "Please choose a file:" default location (path to desktop))
      -- Hazel
      set pathList to quoted form of POSIX path of (theFile as alias)
   end try
   
   -- Get Camera Model
   --set cameraModel to do shell script ExifTool & " -p '${model}' " & pathList
   
   --Get GPS Latitude and Longitude from EXIF data
   do shell script ExifTool & space & ExifGPSLat & space & "-overwrite_original_in_place -P" & space & pathList
   set gpsLat to result
   
   do shell script ExifTool & space & ExifGPSLon & space & "-overwrite_original_in_place -P" & space & pathList
   set gpsLon to result
   
   --do shell script TagTool & space & TagToolOption & quoted form of TagToolNOGPS & space & pathList
   
   -- CONVERT GPS COORDINDATES TO DECIMAL
   if (gpsLat = "") or (gpsLon = "") then
      -- error number -128
      set trail to ""
      set poi to ""
      set country to ""
      set state to "no gps"
      set cityTown to ""
      set jsonCountry to ""
      return {hazelPassesScript:false, hazelOutputAttributes:{trail, poi, state, country, cameraModel}}
      
   else
      -- Set GPS variables separately
      set latDegree to word 3 of gpsLat
      set latMinute to word 5 of gpsLat
      set latSecond to word 6 of gpsLat
      set latDirection to word 7 of gpsLat
      set lonDegree to word 3 of gpsLon
      set lonMinute to word 5 of gpsLon
      set lonSecond to word 6 of gpsLon
      set lonDirection to word 7 of gpsLon
      
      -- Convert Deg,Sec,Min to Decimals
      set latDecimal to latDegree + latMinute / 60 + latSecond / 3600
      set lonDecimal to lonDegree + lonMinute / 60 + lonSecond / 3600
      -- Change Decimals based on Direction
      if (latDirection is equal to "S") then
         set latDecimal to latDecimal * -1 as number --text
      end if
      
      if (lonDirection is equal to "W") then
         set lonDecimal to lonDecimal * -1 as number --text
      end if
      
      set locateP to latDecimal & "," & lonDecimal as string
      
      -- SET GOOGLE API KEY
      set api_key to "AIzaSyCewHXy9mUtqRzUAIY036xxDoAh-26JJys"
      
      set thePath to "https://maps.googleapis.com/maps/api/geocode/json?latlng=" & locateP & "&key=" & api_key
      
      tell application "Location Helper"
         set asDict to reverse geocode location using coordinates {latDecimal, lonDecimal} with API key api_key
      end tell
      
      --tell application "Safari" to open location thePath
      
   end if
   (*
use AppleScript version "2.5"
use framework "Foundation"
use scripting additions

property || : a reference to current application
*)
   set cocoaDict to ||'s NSDictionary's dictionaryWithDictionary:asDict
   set results to cocoaDict's objectForKey:"results"
   
   set poi to {}
   set poiTemp to {}
   
   set route to {}
   set routeTemp to {}
   
   set cityTown to {}
   set cityTownTemp to {}
   
   set stateProvince to {}
   set stateProvinceTemp to {}
   
   set country to {}
   set countryTemp to {}
   
   repeat with anItem in results
      set addressComponents to (anItem's objectForKey:"address_components")
      repeat with aComponent in addressComponents
         set componentTypes to (aComponent's objectForKey:"types")
         if (componentTypes's containsObject:"point_of_interest") then
            set end of poiTemp to (aComponent's objectForKey:"long_name") as text
            set poi to item 1 of poiTemp
         else
            set componentTypes to (aComponent's objectForKey:"types")
            if (componentTypes's containsObject:"establishment") then
               set end of poiTemp to (aComponent's objectForKey:"long_name") as text
               set poi to item 1 of poiTemp
            else
               set componentTypes to (aComponent's objectForKey:"types")
               if (componentTypes's containsObject:"park") then
                  set end of poiTemp to (aComponent's objectForKey:"long_name") as text
                  set poi to item 1 of poiTemp
               else
                  set componentTypes to (aComponent's objectForKey:"types")
                  if (componentTypes's containsObject:"natural_feature") then
                     set end of poiTemp to (aComponent's objectForKey:"long_name") as text
                     set poi to item 1 of poiTemp
                  else
                     set componentTypes to (aComponent's objectForKey:"types")
                     if (componentTypes's containsObject:"colloquial_area") then
                        set end of poiTemp to (aComponent's objectForKey:"long_name") as text
                        set poi to item 1 of poiTemp
                     end if
                  end if
               end if
            end if
         end if
         if (componentTypes's containsObject:"route") then
            set end of routeTemp to (aComponent's objectForKey:"long_name") as text
            set route to item 1 of routeTemp
         else
            if (componentTypes's containsObject:"premise") then
               set end of routeTemp to (aComponent's objectForKey:"long_name") as text
               set route to item 1 of routeTemp
            end if
         end if
         if (componentTypes's containsObject:"locality") then
            set end of cityTownTemp to (aComponent's objectForKey:"long_name") as text
            set cityTown to item 1 of cityTownTemp
         end if
         if (componentTypes's containsObject:"administrative_area_level_1") then
            set end of stateProvinceTemp to (aComponent's objectForKey:"long_name") as text
            set stateProvince to item 1 of stateProvinceTemp
         end if
         if (componentTypes's containsObject:"country") then
            set end of countryTemp to (aComponent's objectForKey:"long_name") as text
            set country to item 1 of countryTemp
         end if
      end repeat
   end repeat
   
   return {hazelPassesScript:true, hazelOutputAttributes:{route, poi, cityTown, stateProvince, country}}
end hazelProcessFile

Re: AppleScript error in preview

PostPosted: Thu Feb 25, 2021 10:31 am
by Mr_Noodle
It doesn't look like the system is returning any error info. I suggest putting logging output in the script to isolate where it may be going wrong.