[Question] Tested Applescript works not with Hazel

Hi,
i searched the Forum for a solution of my following problem and asked Google. So here i am to ask you for help, because i have no more idea.
I scan my receipts, OCR it and extract the date with Hazel's fantastic Date Matching feature. The matched Date (var = receiptDate) will then be used to rename the files with following syntax
Finally i want to set the receiptDate as the Creation Date of the File and created following Applescript, which works perfectly in the Applescript editor.
So i embedded this Applescript into a very simple Hazel rule, which only searches for a pdf and executes the script...
But it doesn't work and i don't know why. In the Script Editor it will in Hazel not!? Can anyone please give me an advice how to get this script working or how i can use the var receiptDate to change the creation date of theFile!?
Thanx in advance.
Thomas
P.S. BTW - I use the latest version of Hazel on a MBP with the latest OS X Yosemite.
i searched the Forum for a solution of my following problem and asked Google. So here i am to ask you for help, because i have no more idea.
I scan my receipts, OCR it and extract the date with Hazel's fantastic Date Matching feature. The matched Date (var = receiptDate) will then be used to rename the files with following syntax
- Code: Select all
[yyyy-mm-dd] receipt - Something i bought.pdf
Finally i want to set the receiptDate as the Creation Date of the File and created following Applescript, which works perfectly in the Applescript editor.
- Code: Select all
---property theFile : alias "Path:To:Your:Example File.extension"
set theFile to choose file
tell application "Finder"
--- Get Name of theFile
set theFileName to (text items 1 thru ((length of (name of theFile as string)) - 4) of (name of theFile as string)) as string
--- Convert Posix Path of theFile to a quoted one
set theQuotedFilePath to quoted form of (POSIX path of (theFile)) as string
--- Extract Date from Filename
set yyyy to text 2 through 5 of theFileName
set mm to text 7 through 8 of theFileName
set dd to text 10 through 11 of theFileName
--- Get actual Date and Time
set currentDate to quoted form of (do shell script "date '+%m/%d/%Y %H:%M':%S")
--- Extract Actual Time from currentDate
set h to text 13 through 14 of currentDate
set m to text 16 through 17 of currentDate
set s to text 19 through 20 of currentDate
--- Define new File-Creation-Date
set creationDate to "'" & mm & "/" & dd & "/" & yyyy & " " & h & ":" & m & ":" & s & "'"
---Change Creation-Date of theFile
do shell script "SetFile -d " & creationDate & " " & theQuotedFilePath
---Change Modification-Date of theFile
do shell script "SetFile -m " & currentDate & " " & theQuotedFilePath
end tell
So i embedded this Applescript into a very simple Hazel rule, which only searches for a pdf and executes the script...
- Code: Select all
tell application "Finder"
--- Get Name of theFile
set theFileName to (text items 1 thru ((length of (name of theFile as string)) - 4) of (name of theFile as string)) as string
--- Convert Posix Path of theFile to a quoted one
set theQuotedFilePath to quoted form of (POSIX path of (theFile)) as string
--- Extract Date from Filename
set yyyy to text 2 through 5 of theFileName
set mm to text 7 through 8 of theFileName
set dd to text 10 through 11 of theFileName
--- Get actual Date and Time
set currentDate to quoted form of (do shell script "date '+%m/%d/%Y %H:%M':%S")
--- Extract Actual Time from currentDate
set h to text 13 through 14 of currentDate
set m to text 16 through 17 of currentDate
set s to text 19 through 20 of currentDate
--- Define new File-Creation-Date
set creationDate to "'" & mm & "/" & dd & "/" & yyyy & " " & h & ":" & m & ":" & s & "'"
---Change Creation-Date of theFile
do shell script "SetFile -d " & creationDate & " " & theQuotedFilePath
---Change Modification-Date of theFile
do shell script "SetFile -m " & currentDate & " " & theQuotedFilePath
end tell
But it doesn't work and i don't know why. In the Script Editor it will in Hazel not!? Can anyone please give me an advice how to get this script working or how i can use the var receiptDate to change the creation date of theFile!?
Thanx in advance.
Thomas
P.S. BTW - I use the latest version of Hazel on a MBP with the latest OS X Yosemite.