Script failing on name

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

Moderator: Mr_Noodle

Script failing on name 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?
pdoak
 
Posts: 5
Joined: Sat Apr 01, 2017 5:04 pm

Re: Script failing on name 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.
Mr_Noodle
Site Admin
 
Posts: 8318
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Re: Script failing on name 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?
pdoak
 
Posts: 5
Joined: Sat Apr 01, 2017 5:04 pm

Re: Script failing on name 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.
Mr_Noodle
Site Admin
 
Posts: 8318
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Re: Script failing on name 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
pdoak
 
Posts: 5
Joined: Sat Apr 01, 2017 5:04 pm

Re: Script failing on name Fri Nov 15, 2019 10:43 am • by Mr_Noodle
So, is it working now or are there still problems with it?
Mr_Noodle
Site Admin
 
Posts: 8318
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City


Return to Support