AppleScript error in preview

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

Moderator: Mr_Noodle

Re: AppleScript error in preview 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.
Mr_Noodle
Site Admin
 
Posts: 8110
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Re: AppleScript error in preview 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.
jfisher
 
Posts: 37
Joined: Sat Feb 25, 2017 7:47 pm

Re: AppleScript error in preview 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.
Mr_Noodle
Site Admin
 
Posts: 8110
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Re: AppleScript error in preview 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.
jfisher
 
Posts: 37
Joined: Sat Feb 25, 2017 7:47 pm

Re: AppleScript error in preview 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?
Mr_Noodle
Site Admin
 
Posts: 8110
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Re: AppleScript error in preview 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.
jfisher
 
Posts: 37
Joined: Sat Feb 25, 2017 7:47 pm

Re: AppleScript error in preview 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.
Mr_Noodle
Site Admin
 
Posts: 8110
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Re: AppleScript error in preview 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
jfisher
 
Posts: 37
Joined: Sat Feb 25, 2017 7:47 pm

Re: AppleScript error in preview 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.
Mr_Noodle
Site Admin
 
Posts: 8110
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Re: AppleScript error in preview 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]
jfisher
 
Posts: 37
Joined: Sat Feb 25, 2017 7:47 pm

Re: AppleScript error in preview Wed Aug 07, 2019 10:04 am • by Mr_Noodle
I'm not seeing the AppleScript error in that log.
Mr_Noodle
Site Admin
 
Posts: 8110
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Previous

Return to Support