Help with theFile and applescript

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

Moderator: Mr_Noodle

Help with theFile and applescript Mon Oct 01, 2012 4:30 pm • by andeersg
Hi, i have created a small applescript that is going to send a notification to my web server when my hazel-rule runs.

My problem is when i want to send the name of the file to the server.

This what i have now:
Code: Select all
set theURL to "http://myserver.com/api.php?type=show&name=" & theFile
do shell script "curl " & quoted form of theURL


It is working, but where i was hoping the name of the show would be there is part of the filepath. How can i extract the filename from "theFile"?
andeersg
 
Posts: 3
Joined: Mon Oct 01, 2012 4:26 pm

Re: Help with theFile and applescript Mon Oct 01, 2012 6:50 pm • by a_freyer
Why not do it all in a shell? I didn't test this, but this should work:

Code: Select all
FILENAME=$(basename $1)
ESCAPED=$(/usr/bin/php -r "echo urlencode(\"$FILENAME\");")
/usr/bin/curl "http://myserver.com/api.php?type=show&name=$ESCAPED"
exit 0
a_freyer
 
Posts: 631
Joined: Tue Sep 30, 2008 9:21 am
Location: Colorado

Re: Help with theFile and applescript Mon Nov 19, 2012 4:29 pm • by andeersg
a_freyer wrote:Why not do it all in a shell? I didn't test this, but this should work:

Code: Select all
FILENAME=$(basename $1)
ESCAPED=$(/usr/bin/php -r "echo urlencode(\"$FILENAME\");")
/usr/bin/curl "http://myserver.com/api.php?type=show&name=$ESCAPED"
exit 0


REALLY slow reply from me here, but i have tried your code but could not get it to work. I am not very good at Shell so i don't know what could be wrong.

Hope someone can clearify this a little.
andeersg
 
Posts: 3
Joined: Mon Oct 01, 2012 4:26 pm

Re: Help with theFile and applescript Mon Nov 19, 2012 4:35 pm • by a_freyer
I've tested this as an embedded script, worked for me.
a_freyer
 
Posts: 631
Joined: Tue Sep 30, 2008 9:21 am
Location: Colorado

Re: Help with theFile and applescript Mon Nov 19, 2012 4:45 pm • by andeersg
Then i must try some more, could not get anything to the server earlier. Will try some more.

Edit:

Don't know why, but i got it to work now. Thank you so much :)
Last edited by andeersg on Mon Nov 19, 2012 5:04 pm, edited 1 time in total.
andeersg
 
Posts: 3
Joined: Mon Oct 01, 2012 4:26 pm

Re: Help with theFile and applescript Mon Nov 19, 2012 4:54 pm • by a_freyer
Try debugging one line at a time. That may help.
a_freyer
 
Posts: 631
Joined: Tue Sep 30, 2008 9:21 am
Location: Colorado


Return to Support