Saturday, December 16, 2017

#1 2002-03-19 01:50:08 pm

Trash Man
Sanitation Department
Registered: 2005-10-20
Posts: 5336

newbie - URL Request

Hello, I admit to be a total newbie to AppleScript. After playing with it for a bit, I can tell it is quite powerful. I'm more of a webguy though, and I was attempting to do some integration.
I stumbled upon an applescript that takes the song name you are listening to and sends it to AIM. I want to take the song name and send it to a url.
For example, go to http://www.blah.net/song.php?song=song% … ist%20name
From there I'd do the rest of the work, inserting it into a little mySQL table where it would be displayed on the front page.
I'd love for this to run without using a browser, but I understand that may be impossible..
Anyways, I thought it would be worth a shot, and was hoping someone could give me some insight.
Thanks!
Kenton Gray


One mans trash is another mans treasure

Offline

 

#2 2002-03-19 04:34:29 am

Rob
Member
From:: Ohio, USA
Registered: 2002-11-20
Posts: 1886

Re: newbie - URL Request

: Hello, I admit to be a total newbie to AppleScript. After playing with it for
: a bit, I can tell it is quite powerful. I'm more of a webguy though, and I
: was attempting to do some integration.
: I stumbled upon an applescript that takes the song name you are listening to
: and sends it to AIM. I want to take the song name and send it to a url.
: For example, go to
: http://www.blah.net/song.php?song=song% … ist%20name
: From there I'd do the rest of the work, inserting it into a little mySQL
: table where it would be displayed on the front page.
: I'd love for this to run without using a browser, but I understand that may
: be impossible..


If you don't want to use a browser, how do you want to "go to" the URL?
A command can be issued without going through a browser, but it will
take the default browser, as set in the Internet control panel, to the
targeted URL.
Example:

Applescript:

open location "[url]http://www.blah.net/song.php?song=song%20name&artist=artist%20name[/url]"

Later,
Rob J

Offline

 

#3 2002-03-19 07:16:47 am

Trash Man
Sanitation Department
Registered: 2005-10-20
Posts: 5336

Re: newbie - URL Request

Ahh, yeah I guess my original wording was a bit ambiguous
What I want to do is send the variables to that script, and have it run on the server. It wouldn't have to output anything, but I suppose its really not as simple as it seems. I just want it to run some sort of send those variables secretly. Maybe an HTTP Post, or something. I suppose it really isn't possible.
My main concern is that I won't be able to use my browser when it takes control of the browser. Or if it will just start to overtake everything in my system, so if I'm working on a photoshop document *bam* theres internet explorer.
This script would more than likely run every minute or 2.
Thanks for your help!

: If you don't want to use a browser, how do you want to "go to" the
: URL?
: A command can be issued without going through a browser, but it will take
: the default browser, as set in the Internet control panel, to the
: targeted URL.
: Example:

Applescript:

open location "[url]http://www.blah.net/song.php?song=song%20name&artist=artist%20name[/url]"

: Later,
: Rob J


One mans trash is another mans treasure

Offline

 

#4 2002-03-19 10:09:20 am

Trash Man
Sanitation Department
Registered: 2005-10-20
Posts: 5336

Re: newbie - URL Request

: What I want to do is send the variables to that script, and have it run on
: the server. It wouldn't have to output anything, but I suppose its really
: not as simple as it seems. I just want it to run some sort of send those
: variables secretly. Maybe an HTTP Post, or something. I suppose it really
: isn't possible.

pre-OS X, you could use URL Access Scripting to send the url request instead of a browser.

Applescript:

tell application "URL Access Scripting"
    activate
    download "[url]http://www.blah.net/song.php?song=song%20name&artist=artist%20name[/url]" to temporaryFile without progress
    quit
end tell

The 'without progress' parameter makes URLAS do its deed w/o any progress bar display, and the temporaryFile (whatever you define the file spec) is the resulting page that would be displayed had the url been fetched with a browser. Other paramters of the 'download' command may have to be used to make the script on the server work.

In OSX I'm to understand there are more options (and a lack of URLAS), but I'm not certain what they are.


One mans trash is another mans treasure


Filed under: url

Offline

 

#5 2002-03-20 07:26:09 am

Trash Man
Sanitation Department
Registered: 2005-10-20
Posts: 5336

Re: newbie - URL Request

hmm that sounds like exactly what i had in mind, but confound my luck I need it to work in OS X.

Thanks for all your help!

If anyone knows any type of replacement for this function in OS X, don't be a stranger smile

Kenton


: pre-OS X, you could use URL Access Scripting to send the url request instead
: of a browser.

Applescript:

tell application "URL Access Scripting"
    activate
    download
"[url]http://www.blah.net/song.php?song=song%20name&artist=artist%20name[/url]"
to temporaryFile without progress
    quit
end tell

: The 'without progress' parameter makes URLAS do its deed w/o any progress bar
: display, and the temporaryFile (whatever you define the file spec) is the
: resulting page that would be displayed had the url been fetched with a
: browser. Other paramters of the 'download' command may have to be used to
: make the script on the server work.
: In OSX I'm to understand there are more options (and a lack of URLAS), but
: I'm not certain what they are.


One mans trash is another mans treasure

Offline

 

#6 2002-03-20 10:17:15 am

Trash Man
Sanitation Department
Registered: 2005-10-20
Posts: 5336

Re: newbie - URL Request

ok now i'm responding to myself, I decided what the heck, even though it was mentioned url access scripting doesn't work in X, i'd try anyways. To my pleasant surprise it worked great!
So here is what I have:

Applescript:

repeat
set the theTime to (the (current date) + 60)
repeat until the (current date) is greater than theTime
end repeat
try
tell application "iTunes"
set artist to (artist of current track)
set song to (name of current track)
end tell
on error
set theSong to "(no song playing)"
end try
try
tell application "URL Access Scripting"
set the temporaryFile to "/Users/kenton/test.php"
activate
download "[url]http://www.hiddenfromeveryone.com/song.php?song=[/url]" & song & "&artist=" & artist & "" to temporaryFile without progress
quit
end tell
end try
end repeat

Now bare in mind I basically cut and paste together random peices of code and just kinda made it up as I go, but everything seems to work. The php script parses it and puts it right on my site!
So now, just 2 issues! great!
1) Every time it runs for a second it takes over my computer, so I'm typing in this and then take control then give back. Just enough to be a slight problem, anything I can do about that?
2) It creates an excess of these temp files, anyway I can delete the file right after it creates them?
I really have to say thanks to everyone here! you guys have been great!


One mans trash is another mans treasure


Filed under: iTunes, url

Offline

 

#7 2002-03-20 10:51:37 am

Trash Man
Sanitation Department
Registered: 2005-10-20
Posts: 5336

Re: newbie - URL Request

: 1) Every time it runs for a second it takes over my computer, so I'm typing
: in this and then take control then give back. Just enough to be a slight
: problem, anything I can do about that?


This could be a result of

Applescript:

set the theTime to (the (current date) + 60)
repeat until the (current date) is greater than theTime
end repeat

Repeats usually take over a script and other processes, so for a more effective pause of 60 seconds try "delay 60" which simply pauses the script execution for 60 seconds. Or investigate a slick osax called Sleep Commands. Depending on why you need to pause execution it may provide a better solution. *sigh* But this too is another step into Classic dependance (until osaxen in X are embraced).
Also, URLAS is a little slow with process switching, so if it works without the 'activate' this may coax it into downloading in the background without taking over the computer.

: 2) It creates an excess of these temp files, anyway I can delete the file
: right after it creates them?


I sometimes use this method of updating a db with a siphonscript page, and when I don't need the result I save the temporary files into OS 9's invisible Temporary Items Folder. They are then automatically deleted (usually). If this isn't available, look to the Finder's scripting dictionary for file manipulation - such as 'tell application "Finder" to delete temporaryFile' which should move the files to the Trash, which can then be emptied by another command if so desired.
My apologies for the tennative tone. OS X is all new territory for me, I've been saving my pennies for a new machine, and a lot of well known scripting techniques have changed dramatically. I suspect that a URL Request in X might be achievable with Terminal commands, and without the Terminal launching using the 'do shell script' AppleScript command...but I've got zero experience in that area ('wget' is striking a bell in my head, dunno why).


One mans trash is another mans treasure


Filed under: Finder

Offline

 

#8 2002-03-20 11:05:25 am

Trash Man
Sanitation Department
Registered: 2005-10-20
Posts: 5336

Re: newbie - URL Request

OH MY GOSH!!!
I was totally mistaken to think that URLAS is no longer with us in Mac OS X.
http://www.applescriptsourcebook.com/ap … pt170.html
It's there, and hasn't changed. Cool. It's good news for a lot of my scripts (and yet still more incentive to splurge ahead of budget).
Depending on your server setup, some of the new Web Services may come in handy.
http://www.apple.com/applescript/macosx/web_services/


One mans trash is another mans treasure

Offline

 

#9 2002-03-20 11:38:36 am

Trash Man
Sanitation Department
Registered: 2005-10-20
Posts: 5336

Re: newbie - URL Request

Wow I have to say, you can't buy support this good smile
Thanks to you guys, everything works great!
If anyone wants to see my script in action you are more than welcome to check out my little site, www.pocketlint.net; everything is still really early, but all the script no longer takes control of everything and its really concise.
for the curious here is the completed [for now] code!

Applescript:

repeat
delay 10
try
tell application "iTunes"
set theArtist to (artist of current track)
set theSong to (name of current track)
end tell
on error
set theSong to "(no song playing)"
end try
try
tell application "URL Access Scripting"
set the temporaryFile to "/Users/kenton/tmp/test.php"
download "[url]http://www.pocketlint.net/song.php?song=[/url]" & (theSong) & "&artist=" & (theArtist) & "" to temporaryFile without progress
quit
end tell
end try
end repeat

and if anyone would like to see the php and mysql backend feel free to email me!
Again, thanks guys, if any of you need any help on any php or anything else, I'll be glad to assist!

: This could be a result of

Applescript:

set the theTime to (the (current date) + 60)
repeat until the (current date) is greater than theTime
end repeat

: Repeats usually take over a script and other processes, so for a more
: effective pause of 60 seconds try "delay 60" which simply pauses
: the script execution for 60 seconds. Or investigate a slick osax called
: Sleep Commands . Depending on why you need to pause execution it may
: provide a better solution. *sigh* But this too is another step into
: Classic dependance (until osaxen in X are embraced).
: Also, URLAS is a little slow with process switching, so if it works without
: the 'activate' this may coax it into downloading in the background without
: taking over the computer.
: I sometimes use this method of updating a db with a siphonscript page, and
: when I don't need the result I save the temporary files into OS 9's
: invisible Temporary Items Folder. They are then automatically deleted
: (usually). If this isn't available, look to the Finder's scripting
: dictionary for file manipulation - such as 'tell application
: "Finder" to delete temporaryFile' which should move the files to
: the Trash, which can then be emptied by another command if so desired.
: My apologies for the tennative tone. OS X is all new territory for me, I've
: been saving my pennies for a new machine, and a lot of well known
: scripting techniques have changed dramatically. I suspect that a URL
: Request in X might be achievable with Terminal commands, and without the
: Terminal launching using the 'do shell script' AppleScript command...but
: I've got zero experience in that area ('wget' is striking a bell in my
: head, dunno why).


One mans trash is another mans treasure


Filed under: iTunes, url

Offline

 

#10 2002-03-21 01:09:10 pm

kel
Member
Registered: 2002-11-20
Posts: 2031

Re: newbie - URL Request

Do idle handlers work in OSX? For example, save the following as a stay open application:

Applescript:

on idle
 -- your stuff goes here
 tell application "Finder"
  say (time string of (current date))
 end tell
 -- end your stuff
 return 60
end idle

gl, Kel.


Kel


Filed under: Finder

Offline

 

#11 2002-03-21 09:41:38 am

Krioni
Member
From:: New York, NY
Registered: 2002-11-20
Posts: 245
Website

Re: newbie - URL Request

Kenton,

I thought the following might be helpful. I took your code from the "finished - for now" post, and added a few things. First, I separated a few things into handlers, so the code is somewhat easier to read. Then, I put in an idle handler (rather than using a delay-repeat loop). If you take this script, save it as a Stay-Open application from Script Editor, it will run every ten seconds. The 'on idle' handler does the following:

When your applet is idle, it runs the idle handler. The idle handler should return the number of seconds the applet should wait in idle mode before running the idle handler again. I basically says "OK, I've done some stuff, and now I'm going to give myself an X second break before I do anything again." (where X is the number returned by the idle handler). Take a look at the code below, and see if it makes sense.

Applescript:

on run
   sendSong()
end run

on idle
   sendSong()
   return 10 -- number of seconds before next time it does something
end idle

on sendSong()
   try
       set myURL to getURL() -- get the URL from iTune's current song
       tell application "URL Access Scripting"
           set the temporaryFile to "/Users/krioni/tmp/test.php"
           download myURL to temporaryFile replacing yes without progress
           quit
       end tell
   end try
end sendSong

on getURL()
   try
       tell application "iTunes"
           set theArtist to (artist of current track)
           set theSong to (name of current track)
       end tell
   on error
       set theSong to "(no song playing)"
       set theArtist to "(no song playing)"
   end try
   return "[url]http://www.pocketlint.net/song.php?song=[/url]" & (theSong) & "&artist=" & (theArtist) & ""
end getURL


Filed under: iTunes, url

Offline

 

#12 2002-03-22 08:08:19 am

Trash Man
Sanitation Department
Registered: 2005-10-20
Posts: 5336

Re: newbie - URL Request

If you are working out of 'X' there is the lovely Akua "pause for" - lovely because it doesn't lock up the CPU.


One mans trash is another mans treasure

Offline

 

#13 2002-03-24 04:07:26 am

Krioni
Member
From:: New York, NY
Registered: 2002-11-20
Posts: 245
Website

Re: newbie - URL Request

:  The bit missing there, I would guess, was 'and'
:  .If you are working out of 'X' there is the lovely
: Akua " pause for" - lovely because it doesn't lock up the CPU.



Also, the idle handler is still probably the best way to go, since it uses built-in AppleScript, and runs on most version of AppleScript.

Offline

 

#14 2002-03-24 05:10:23 am

Trash Man
Sanitation Department
Registered: 2005-10-20
Posts: 5336

Re: newbie - URL Request

I agree that an idle handler is the best idea.


One mans trash is another mans treasure

Offline

 

Board footer

Powered by FluxBB

RSS (new topics) RSS (active topics)