Page 1 of 1

Cannot get a simple Applescript to run

PostPosted: Wed Dec 30, 2020 6:55 pm
by prop_md
Hello,

I am new at using Applescript with Hazel, but I have been using Hazel itself for years.

I ultimately need to move a file to a new folder. But, I am stuck on what it seemingly the simplest task — getting the name of the file passed to the script.

I am trying this:

Code: Select all
set theFileName to theFile as text
display dialog theFileName


But this gives an error.

Any help in getting me started would be much appreciated.

Thanks!

Re: Cannot get a simple Applescript to run

PostPosted: Thu Dec 31, 2020 11:33 am
by Mr_Noodle
Note that theFile is an alias to the file and when converted to text, has the full path, not just the filename. You may want to search around on how to extract the filename part of the path.

Re: Cannot get a simple Applescript to run

PostPosted: Thu Dec 31, 2020 11:44 am
by prop_md
Mr_Noodle wrote:Note that theFile is an alias to the file and when converted to text, has the full path, not just the filename. You may want to search around on how to extract the filename part of the path.


I have no problem extracting a portion of a string.

But, shouldn't my code run as-is?

Re: Cannot get a simple Applescript to run

PostPosted: Thu Dec 31, 2020 1:05 pm
by Mr_Noodle
What's the error you are getting?

Re: Cannot get a simple Applescript to run

PostPosted: Thu Dec 31, 2020 2:13 pm
by prop_md
The error is a Hazel notification (upper right hand of screen) stating "AppleScript Failed" "Error executing AppleScript on file XXX".

Thank you.

Re: Cannot get a simple Applescript to run

PostPosted: Mon Jan 04, 2021 12:21 pm
by Mr_Noodle
Usually the logs have better errors but in this case, try doing "tell application "System Events" to display dialog theFileName"