Register Guidelines E-Books Search Today's Posts Mark Forums Read

Go Back   MobileRead Forums > E-Book Formats > Kindle Formats

Notices

Reply
 
Thread Tools Search this Thread
Old 02-09-2010, 06:09 AM   #1
pdurrant
The Grand Mouse 高貴的老鼠
pdurrant ought to be getting tired of karma fortunes by now.pdurrant ought to be getting tired of karma fortunes by now.pdurrant ought to be getting tired of karma fortunes by now.pdurrant ought to be getting tired of karma fortunes by now.pdurrant ought to be getting tired of karma fortunes by now.pdurrant ought to be getting tired of karma fortunes by now.pdurrant ought to be getting tired of karma fortunes by now.pdurrant ought to be getting tired of karma fortunes by now.pdurrant ought to be getting tired of karma fortunes by now.pdurrant ought to be getting tired of karma fortunes by now.pdurrant ought to be getting tired of karma fortunes by now.
 
pdurrant's Avatar
 
Posts: 71,491
Karma: 306214458
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.
Attached Files
File Type: zip PythonWrapper.zip (29.9 KB, 984 views)

Last edited by pdurrant; 02-09-2010 at 06:11 AM.
pdurrant is offline   Reply With Quote
Old 02-09-2010, 08:18 AM   #2
pthwaite
Fanatic
pthwaite has a complete set of Star Wars action figures.pthwaite has a complete set of Star Wars action figures.pthwaite has a complete set of Star Wars action figures.pthwaite has a complete set of Star Wars action figures.pthwaite has a complete set of Star Wars action figures.
 
pthwaite's Avatar
 
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.
pthwaite is offline   Reply With Quote
Advert
Old 04-27-2010, 01:13 PM   #3
bpwhistler
Member
bpwhistler began at the beginning.
 
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.
bpwhistler is offline   Reply With Quote
Old 04-27-2010, 02:25 PM   #4
bpwhistler
Member
bpwhistler began at the beginning.
 
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 03:24 PM.
bpwhistler is offline   Reply With Quote
Old 04-28-2010, 03:22 PM   #5
bpwhistler
Member
bpwhistler began at the beginning.
 
Posts: 14
Karma: 10
Join Date: Oct 2008
Device: Palm III, IV, Treo, Centro, MacBook, iPod Touch...and someday a tablet
Quote:
Originally Posted by pdurrant View Post
Obviously, this would need to be changed if your target python script takes different parameters. I find it very useful as-is.
I found it very usefua as-is also. I'm an awful NOOB at Terminal, and I've never used Python until yesterday. It functioned beautifully using the Python script it is currently coded for. I REALLY liked the drag-and-drop functionality.

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 03:26 PM.
bpwhistler is offline   Reply With Quote
Advert
Old 04-28-2010, 03:39 PM   #6
pdurrant
The Grand Mouse 高貴的老鼠
pdurrant ought to be getting tired of karma fortunes by now.pdurrant ought to be getting tired of karma fortunes by now.pdurrant ought to be getting tired of karma fortunes by now.pdurrant ought to be getting tired of karma fortunes by now.pdurrant ought to be getting tired of karma fortunes by now.pdurrant ought to be getting tired of karma fortunes by now.pdurrant ought to be getting tired of karma fortunes by now.pdurrant ought to be getting tired of karma fortunes by now.pdurrant ought to be getting tired of karma fortunes by now.pdurrant ought to be getting tired of karma fortunes by now.pdurrant ought to be getting tired of karma fortunes by now.
 
pdurrant's Avatar
 
Posts: 71,491
Karma: 306214458
Join Date: Jul 2007
Location: Norfolk, England
Device: Kindle Voyage
Quote:
Originally Posted by bpwhistler View Post
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?
Note that this Applescript doesn't have the name of the python script in the code - it's stored when you choose the script to use. So to use it with a script that uses the same paramters, just choose the different script.

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.
pdurrant is offline   Reply With Quote
Old 04-28-2010, 03:44 PM   #7
bpwhistler
Member
bpwhistler began at the beginning.
 
Posts: 14
Karma: 10
Join Date: Oct 2008
Device: Palm III, IV, Treo, Centro, MacBook, iPod Touch...and someday a tablet
Quote:
Originally Posted by pdurrant View Post
Note that this Applescript doesn't have the name of the python script in the code - it's stored when you choose the script to use.
Ahhh...I didn't check the original AppleScript, just the one that I had already used and associated to a Python Script.

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.
bpwhistler is offline   Reply With Quote
Old 04-28-2010, 03:58 PM   #8
bpwhistler
Member
bpwhistler began at the beginning.
 
Posts: 14
Karma: 10
Join Date: Oct 2008
Device: Palm III, IV, Treo, Centro, MacBook, iPod Touch...and someday a tablet
Quote:
Originally Posted by pdurrant View Post
Note that this Applescript doesn't have the name of the python script in the code - it's stored when you choose the script to use.
Are you sure? I just downloaded a new copy from the first post in this thread, and the name of the Python script was already in the AppleScript (I didn't run the script...just unzipped it and opened it in AS Editor). The only thing it needed was the path to the script...and a PID.

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 04:18 PM.
bpwhistler is offline   Reply With Quote
Old 04-28-2010, 05:45 PM   #9
pdurrant
The Grand Mouse 高貴的老鼠
pdurrant ought to be getting tired of karma fortunes by now.pdurrant ought to be getting tired of karma fortunes by now.pdurrant ought to be getting tired of karma fortunes by now.pdurrant ought to be getting tired of karma fortunes by now.pdurrant ought to be getting tired of karma fortunes by now.pdurrant ought to be getting tired of karma fortunes by now.pdurrant ought to be getting tired of karma fortunes by now.pdurrant ought to be getting tired of karma fortunes by now.pdurrant ought to be getting tired of karma fortunes by now.pdurrant ought to be getting tired of karma fortunes by now.pdurrant ought to be getting tired of karma fortunes by now.
 
pdurrant's Avatar
 
Posts: 71,491
Karma: 306214458
Join Date: Jul 2007
Location: Norfolk, England
Device: Kindle Voyage
Quote:
Originally Posted by bpwhistler View Post
Are you sure? I just downloaded a new copy from the first post in this thread, and the name of the Python script was already in the AppleScript (I didn't run the script...just unzipped it and opened it in AS Editor). The only thing it needed was the path to the script...and a PID.
Oh - I see what you mean. No, the name gets completely over-written when you choose the script to use.
pdurrant is offline   Reply With Quote
Old 07-23-2011, 02:57 AM   #10
MichaelMaggs
Junior Member
MichaelMaggs began at the beginning.
 
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
MichaelMaggs is offline   Reply With Quote
Old 07-23-2011, 03:43 AM   #11
pdurrant
The Grand Mouse 高貴的老鼠
pdurrant ought to be getting tired of karma fortunes by now.pdurrant ought to be getting tired of karma fortunes by now.pdurrant ought to be getting tired of karma fortunes by now.pdurrant ought to be getting tired of karma fortunes by now.pdurrant ought to be getting tired of karma fortunes by now.pdurrant ought to be getting tired of karma fortunes by now.pdurrant ought to be getting tired of karma fortunes by now.pdurrant ought to be getting tired of karma fortunes by now.pdurrant ought to be getting tired of karma fortunes by now.pdurrant ought to be getting tired of karma fortunes by now.pdurrant ought to be getting tired of karma fortunes by now.
 
pdurrant's Avatar
 
Posts: 71,491
Karma: 306214458
Join Date: Jul 2007
Location: Norfolk, England
Device: Kindle Voyage
Quote:
Originally Posted by MichaelMaggs View Post
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?
Well, you're trying to use an old AppleScript that I wrote over a year ago, instead of using the really nice AppleScript that Apprentice Alf et. al. have provided and updated for us.

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.
pdurrant is offline   Reply With Quote
Old 07-23-2011, 05:00 AM   #12
MichaelMaggs
Junior Member
MichaelMaggs began at the beginning.
 
Posts: 2
Karma: 10
Join Date: Jul 2011
Device: none
Ah, OK. Thank you.

Michael
MichaelMaggs is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Classic Nook and Mac users just_jeepin Barnes & Noble NOOK 1 06-22-2010 12:52 PM
Mac users that are Reader owners, help a new Mac owner AnemicOak Sony Reader 8 06-12-2010 04:36 PM
Seriously thoughtful How many Mac users on this site? mwheinz Lounge 18 10-22-2009 09:16 AM
Question for mac users jerryleejr Sony Reader 6 02-06-2008 12:59 AM
Mac OS X lit2rtf AppleScript thingy FourOhFour Sony Reader 11 08-11-2007 12:02 AM


All times are GMT -4. The time now is 10:07 AM.


MobileRead.com is a privately owned, operated and funded community.