Page 1 of 1

Script failing on name

PostPosted: Tue Nov 12, 2019 7:10 am
by pdoak
I have a hazel rule which invokes the following Applescript:

Code: Select all
use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions

on hazelProcessFile(theFile)
   set getDate to ((path to scripts folder as text) & "xxx:getDatePython.scpt")
   
   set dateVar to run script alias getDate with parameters {theFile}
   set TID to AppleScript's text item delimiters
   set AppleScript's text item delimiters to " "
   try
      set pyYY to word 1 of dateVar
      set pyMM to word 2 of dateVar
      set pyDD to word 3 of dateVar
      set pyValue to word 4 of dateVar
      set pyName to (words 5 thru -1 of dateVar) as text
   end try
   
   set AppleScript's text item delimiters to TID
   
   return {hazelExportTokens:{exportName:pyName as string, yyear:pyYY as string, mmonth:pyMM as string, dday:pyDD as string, vvalue:pyValue as string}}
   
end hazelProcessFile


The AppleScript above runs a python script which works apart from when the file name has a "(" in the name. Is there a way that I can get around this issue?

Re: Script failing on name

PostPosted: Tue Nov 12, 2019 11:07 am
by Mr_Noodle
You probably need to quote the file when you send it to the python script.

Re: Script failing on name

PostPosted: Tue Nov 12, 2019 11:23 am
by pdoak
Okay. I changed the applescrpit line to:

Code: Select all
set dateVar to run script alias getDate with parameters {quoted form of theFile}


but it still did not work.

Is that what you meant?

Re: Script failing on name

PostPosted: Wed Nov 13, 2019 11:33 am
by Mr_Noodle
How does it run outside of Hazel? If you see the same problem there then it's not really a Hazel issue. I would suggest printing out variables at different points, including the arguments before you send them to the python script.

Re: Script failing on name

PostPosted: Thu Nov 14, 2019 3:47 pm
by pdoak
I could not get the original script to work but amended the script such that I did not call another AppleScript as below and set the path to the "quoted form":

Code: Select all
use AppleScript version "2.4" -- Yosemite (10.10) or later
use scripting additions

on hazelProcessFile(theFile)
   --set getDate to ((path to scripts folder as text) & "xxx:getDatePython.scpt")
   --set dateVar to run script alias getDate with parameters {theFile}
   
   set shell_script to ""
   set python_comm to "/usr/local/bin/python3  /Users/xxx/Developer/Python/utils/date_reader_hazel.py -v -f "
   set file_path to quoted form of (POSIX path of theFile)
   set shell_script to shell_script & " " & python_comm & file_path

   set dateVar to (do shell script shell_script)
   
   
   set TID to AppleScript's text item delimiters
   set AppleScript's text item delimiters to " "
   try
      set pyYY to word 1 of dateVar
      set pyMM to word 2 of dateVar
      set pyDD to word 3 of dateVar
      set pyValue to word 4 of dateVar
      set pyName to (words 5 thru -1 of dateVar) as text
   end try
   
   set AppleScript's text item delimiters to TID
   
   return {hazelExportTokens:{exportName:pyName as string, yyear:pyYY as string, mmonth:pyMM as string, dday:pyDD as string, vvalue:pyValue as string}}
   
end hazelProcessFile

Re: Script failing on name

PostPosted: Fri Nov 15, 2019 10:43 am
by Mr_Noodle
So, is it working now or are there still problems with it?