Unable to get filename with basename

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

Moderator: Mr_Noodle

Unable to get filename with basename Tue Oct 22, 2013 6:59 am • by uncompressed
Hi,

I'm learning how to write some simple scripts with Hazel and am having trouble with what I thought is fairly basic.

I'm triggering this script when the file Budget.numbers is detected in /Users/xxxx/Documents/Personal Docs/

This is script

Code: Select all
filename=$(basename “$1”)
echo $1
echo $filename


The results I get from the log file is:

/Users/xxxx/Documents/Personal Docs/Budget.numbers
Personal

Why is my $filename output "Personal" instead of "Budget.numbers"?
uncompressed
 
Posts: 3
Joined: Tue Oct 22, 2013 6:51 am

Re: Unable to get filename with basename Tue Oct 22, 2013 3:25 pm • by Mr_Noodle
This is a bit outside of Hazel support, but I think it's related to the fact that $1 contains a space. Also, it looks like you are using "smart quotes" around $1. Not sure if that's just how you formatted it in the post or how it actually appears in the script.
Mr_Noodle
Site Admin
 
Posts: 11948
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Re: Unable to get filename with basename Tue Oct 22, 2013 6:03 pm • by uncompressed
That was just the format in the forum post.

Also, if I run this script as a standalone outside of Hazel, it works fine.
uncompressed
 
Posts: 3
Joined: Tue Oct 22, 2013 6:51 am

Re: Unable to get filename with basename Wed Oct 23, 2013 6:40 am • by uncompressed
Ok, did some more testing. If I remove the spaces in the affected directory, then the script works.
uncompressed
 
Posts: 3
Joined: Tue Oct 22, 2013 6:51 am

Re: Unable to get filename with basename Fri Nov 08, 2013 10:16 am • by davkyles
Are you using Mavericks? Smart quotes was being applied automatically for me after the upgrade. It looks like a new default in System Preferences > Keyboard > Text > Use smart quotes and dashes has been added.
davkyles
 
Posts: 1
Joined: Wed Sep 14, 2011 10:41 pm

Re: Unable to get filename with basename Fri Nov 08, 2013 11:49 am • by Mr_Noodle
Yes, this is an unfortunate change. This will be properly fixed in the next update.
Mr_Noodle
Site Admin
 
Posts: 11948
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Re: Unable to get filename with basename Fri Jan 24, 2014 3:38 pm • by samberlu
Hold on guys, lets get back to the problem which is that Hazel fails this basic command when there are spaces.

That's a problem, no?
samberlu
 
Posts: 4
Joined: Thu Jan 23, 2014 1:46 pm

Re: Unable to get filename with basename Fri Jan 24, 2014 4:38 pm • by Mr_Noodle
No, that was not the problem. The smart quotes in the script was causing the failure and Hazel's editor was fixed to turn them off. If you have an example indicating otherwise, please post it.
Mr_Noodle
Site Admin
 
Posts: 11948
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City

Re: Unable to get filename with basename Fri Jan 24, 2014 5:18 pm • by samberlu
From what uncompressed said the smart quotes where just a forum thing and the script worked fine outside Hazel.

When I run basename through applescript it doesn't return the correct thing due to the spaces in folder and filenames.
Anyway I've resorted to using sed 's/.*\\///'" .
samberlu
 
Posts: 4
Joined: Thu Jan 23, 2014 1:46 pm

Re: Unable to get filename with basename Tue Jan 28, 2014 1:13 pm • by Mr_Noodle
Not a forum thing. The script editor in Hazel was adding the smart quotes.
Mr_Noodle
Site Admin
 
Posts: 11948
Joined: Sun Sep 03, 2006 1:30 am
Location: New York City


Return to Support