Page 1 of 1

Help with theFile and applescript

PostPosted: 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"?

Re: Help with theFile and applescript

PostPosted: 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

Re: Help with theFile and applescript

PostPosted: 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.

Re: Help with theFile and applescript

PostPosted: Mon Nov 19, 2012 4:35 pm
by a_freyer
I've tested this as an embedded script, worked for me.

Re: Help with theFile and applescript

PostPosted: 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 :)

Re: Help with theFile and applescript

PostPosted: Mon Nov 19, 2012 4:54 pm
by a_freyer
Try debugging one line at a time. That may help.