Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

dutchchilly

macrumors member
Original poster
Jun 29, 2009
38
0
This is my wish:

-I want my MacMini to look (at intervals) in a mysql table to see if records with an url have been added.
-If so, I want to run this url on the MacMini, and delete the record. As it is a .torrent file it will be downloaded to the 'download' folder, where my uTorrents will pick it up from there.

Is this possible with AppleScript? Or should I be thinking of creating a native app in XCode?
 
This is possible to accomplish via AppleScript. Your problem will likely be determining which entries are new/unprocessed and which are old/processed.

But the way to do it is to do something like:

Code:
set the_table to "files"
set the_database to "mydatabase"
(do shell script "/usr/local/mysql/bin/mysql -u root " & " -D " & "\\`" & the_database & "\\`" & " -e \"" & "SELECT * FROM " & "\\`" & the_table & "\\`" & "\"")
 
I'd be most inclined (because I know it better) to use shell for this rather than applescript... you could wrap the shell script in an applescript if that was important. I don't know mysql's commandline parameters, but I'd imagine it would look something like:
Code:
mysql -<user switch> <username> -<password switch> <password> -<dbname switch> <database name> -<query to run switch> "select key, url from myURLTable limit 1" > tmpFile.out
awk -F<mysql field delimiter> '{system("curl $2 > ~/Downloads/$1.torrent; mysqlDelete $1")}'

Where mysqlDelete was a secondary shell script that takes a key and deletes the row from myURLTable with that key (I didn't feel like dealing with escaping in the awk system command). The curl syntax is incomplete, i just don't know off the top of my head how to download from a particular URL to a particular local file. man curl or googling for "man curl" should get you there.

-Lee
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.