02-09-2010, 07:09 AM | #1 |
The Grand Mouse 高貴的老鼠
Posts: 72,502
Karma: 309060442
Join Date: Jul 2007
Location: Norfolk, England
Device: Kindle Voyage
|
Useful Applescript for Mac OS X users
Mac users usually hate mucking about on a command line. I certainly don't like it. Personally, I think the Terminal application should have been an optional install (perhaps with the Developer Tools). But I digress...
Driven by this dislike, I developed an Applescript wrapper for programs that only come as command lines. For example, python scripts. I enclose a sample Applescript to demonstrate how to do it. This Applescript runs python scripts. It demonstrates how to set up a persistent variable that can store the path to the python script to be run, so no changes need to be made to the Applescript to run different python scripts. The Applescript only ever prompts for a new python script when it cannot locate the old one. It also shows how a persistent variable can be used to store a user-specific value, which can later be passed to the python script or used elsewhere. Again, eliminating the need to manually edit the Applescript. As written, the persistent value is prompted for when first run, or when run on its own by double-clicking the icon. If it's already been supplied, it's not prompted for when the Applescript is run by drag&drop of files and/or folders onto the icon. Speaking of drag&drop, this Applescript also shows how to process files and folders dropped onto the Applescript, so that each file (of a particular type or types) can be passed individually to the chosen script, and how to manipulate the file names to generate an output file name based on the input file names. Some users may find it useful in its current form, but only if they have a suitable python script already, as the attached file contains no python scripts itself. Currently, the Applescript calls the chosen python script with a command line like python [pythonscript] [infile] [outfile] [persistent value] Obviously, this would need to be changed if your target python script takes different parameters. I find it very useful as-is. I hope others find it educational and useful. Last edited by pdurrant; 02-09-2010 at 07:11 AM. |
02-09-2010, 09:18 AM | #2 |
Fanatic
Posts: 597
Karma: 430
Join Date: Aug 2008
Location: Ellesmere Port, UK
Device: DR1000S Sony PRS505 iPad iPhone
|
Thanks for this, it normally takes me ages to get the terminal command prompts to do what I want (used to DOS adn not unix) so this will help a lot.
|
Advert | |
|
04-27-2010, 02:13 PM | #3 |
Member
Posts: 14
Karma: 10
Join Date: Oct 2008
Device: Palm III, IV, Treo, Centro, MacBook, iPod Touch...and someday a tablet
|
This is an excellent script. It makes life incredibly easy. Thanks.
|
04-27-2010, 03:25 PM | #4 |
Member
Posts: 14
Karma: 10
Join Date: Oct 2008
Device: Palm III, IV, Treo, Centro, MacBook, iPod Touch...and someday a tablet
|
Just out of curiosity...where are the Kindle iPod files located on my Mac?
edit...answered in Alfsapprentice...thanks. Last edited by bpwhistler; 04-28-2010 at 04:24 PM. |
04-28-2010, 04:22 PM | #5 | |
Member
Posts: 14
Karma: 10
Join Date: Oct 2008
Device: Palm III, IV, Treo, Centro, MacBook, iPod Touch...and someday a tablet
|
Quote:
I'm also a NOOB to AppleScript. I've played with it through the years, but never delved into it. I typically take somebody else's script and then "tweak" it to suit my needs. I opened this script and looked at it in AppleScript Editor ...unfortunately, I didn't even understand the basics. Could I take a Python script that is designed for another similar task, and just replace every instance of the Python script currently in the script...and get similar functions? Do you use this "wrapper" on all of your Python scripts? I would just try it out...but I don't currently have any of the file types the other Python scripts I'm thinking about are designed for. Thanks. Last edited by bpwhistler; 04-28-2010 at 04:26 PM. |
|
Advert | |
|
04-28-2010, 04:39 PM | #6 | |
The Grand Mouse 高貴的老鼠
Posts: 72,502
Karma: 309060442
Join Date: Jul 2007
Location: Norfolk, England
Device: Kindle Voyage
|
Quote:
If you want to use it with a script that takes different parameters, you'll need to change the code that builds the command to be executed. |
|
04-28-2010, 04:44 PM | #7 | |
Member
Posts: 14
Karma: 10
Join Date: Oct 2008
Device: Palm III, IV, Treo, Centro, MacBook, iPod Touch...and someday a tablet
|
Quote:
With regards to the "different paramenters..." I don't have a clue. It will be a trial and error thing when I actually try it on one of the other Python scripts I have. Thanks very much. |
|
04-28-2010, 04:58 PM | #8 | |
Member
Posts: 14
Karma: 10
Join Date: Oct 2008
Device: Palm III, IV, Treo, Centro, MacBook, iPod Touch...and someday a tablet
|
Quote:
Am I missing something. edit: I don't mean to presume. YOU wrote the script. I just see the name of the Python Script I utilized it for already present. I don't know if this name will be changed in the script when I choose the path to a differently named Python script. Like I said...NOOB with little understanding. Last edited by bpwhistler; 04-28-2010 at 05:18 PM. |
|
04-28-2010, 06:45 PM | #9 | |
The Grand Mouse 高貴的老鼠
Posts: 72,502
Karma: 309060442
Join Date: Jul 2007
Location: Norfolk, England
Device: Kindle Voyage
|
Quote:
|
|
07-23-2011, 03:57 AM | #10 |
Junior Member
Posts: 2
Karma: 10
Join Date: Jul 2011
Device: none
|
I'm very new to this forum, and suspect I may be missing something. Opening the zip file produces a script called MobiPocket Unlocker, which asks for a PID (I'm using the default) then asks for a script, presumably the py script. On selecting that, the script seems to close with no action. What am I doing wrong?
Michael |
07-23-2011, 04:43 AM | #11 | |
The Grand Mouse 高貴的老鼠
Posts: 72,502
Karma: 309060442
Join Date: Jul 2007
Location: Norfolk, England
Device: Kindle Voyage
|
Quote:
Google for Apprentice Alf, download the tools archive you'll find linked from his blog, and use the DeDRM AppleScript you'll find in there. |
|
07-23-2011, 06:00 AM | #12 |
Junior Member
Posts: 2
Karma: 10
Join Date: Jul 2011
Device: none
|
Ah, OK. Thank you.
Michael |
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Classic Nook and Mac users | just_jeepin | Barnes & Noble NOOK | 1 | 06-22-2010 01:52 PM |
Mac users that are Reader owners, help a new Mac owner | AnemicOak | Sony Reader | 8 | 06-12-2010 05:36 PM |
Seriously thoughtful How many Mac users on this site? | mwheinz | Lounge | 18 | 10-22-2009 10:16 AM |
Question for mac users | jerryleejr | Sony Reader | 6 | 02-06-2008 01:59 AM |
Mac OS X lit2rtf AppleScript thingy | FourOhFour | Sony Reader | 11 | 08-11-2007 01:02 AM |