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

Previous

Return to Support