Cannot get a simple Applescript to run

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

Moderator: Mr_Noodle

Cannot get a simple Applescript to run 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!
prop_md
 
Posts: 3
Joined: Wed Dec 30, 2020 6:50 pm

Re: Cannot get a simple Applescript to run 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.
Mr_Noodle
Site Admin
 
Posts: 11868
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Re: Cannot get a simple Applescript to run 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?
prop_md
 
Posts: 3
Joined: Wed Dec 30, 2020 6:50 pm

Re: Cannot get a simple Applescript to run Thu Dec 31, 2020 1:05 pm • by Mr_Noodle
What's the error you are getting?
Mr_Noodle
Site Admin
 
Posts: 11868
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Re: Cannot get a simple Applescript to run 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.
prop_md
 
Posts: 3
Joined: Wed Dec 30, 2020 6:50 pm

Re: Cannot get a simple Applescript to run 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"
Mr_Noodle
Site Admin
 
Posts: 11868
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City


Return to Support