appscript AppleScript translator
I’m about to convert my Dining After Midnight site from FileMaker Pro to Django/SQLite. I decided to write a Python/appscript script to do the data transfer. While there aren’t that many restaurants in the list (San Diego is not a city that never sleeps), I have several other FileMaker databases I’d like to convert either to Django/SQLite or just SQLite, and this seemed like a good time to come up with an easy transfer process.
As I wrote in my earlier article about using appscript to control iTunes, the appscript help is really for Python programmers who already know appscript. If you’re comfortable with AppleScript, you will probably find ASTranslate (on the appscript download page) invaluable. It will take AppleScript “tell” blocks and convert them to appscript code.
For example:
[toggle code]
-
tell application "FileMaker Pro"
-
tell database "After Midnight"
- show every record
- end tell
-
tell database "After Midnight"
- end tell
Paste this into ASTranslate and it will become:
- app(u'/Applications/Apps/FileMaker Pro 6 Folder/FileMaker Pro.app').databases['After Midnight'].records.show()
It’s still up to you to turn this into more readable Python, but that’s a much easier task than trying to guess at what appscript is expecting.
- import appscript
- fm = appscript.app(u'/Applications/Apps/FileMaker Pro 6 Folder/FileMaker Pro.app')
- db = fm.databases['After Midnight']
- records = db.records.show()
And finally, the better choice for opening FileMaker is probably to use the ID, in case you move it later:
- fm = appscript.app(id="com.filemaker.filemakerpro")
If you’re using a more modern version of FileMaker Pro, you’ll also use a different ID.
With ASTranslate, as long as you can construct the “tell” block(s) in AppleScript, you can quickly get the necessary appscript calls.
In response to Using appscript in Python to control GUI applications: The appscript module for Python lets you control scriptable applications on the command line without having to coordinate your command-line script with your Applescript applications.
- appscript
- Appscript is a high-level, user-friendly MacPython to Apple event bridge that allows you to control scriptable Mac OS X applications using ordinary Python scripts. Appscript makes MacPython a serious alternative to Apple’s own AppleScript language for automating your Mac.
- Dining After Midnight
- There is nothing quite like the hunger you get at three in the morning when everyone else has gone to sleep. If you’re hanging with the late crowd in San Diego, come and see where you can time out for a bite after midnight!
- Django
- “Django is a high-level Python Web framework that encourages rapid development and clean, pragmatic design.” Oh, the sweet smell of pragmatism.
More Python
- Multiple Input Fields with multiple inheritance
- We needed to display one TextField as either a TextInput or a Textarea, depending on the value in the field. Multiple inheritance makes it easy, if a bit wonky.
- PyTown
- General rambling in code regarding Python, Mailman, and Django.
- Thinking Python: Django cache expiration time
- Django sets the expiration time when data is cached. Sometimes it makes more sense to expire data dynamically based on later changes to the database. Does this mean a change to CacheClass? Not necessarily.
- Django Twitter tag and RSS object
- I wanted to embed my twitter feed into my Django blog, and didn’t see any simple RSS readers for Python that did what I wanted.
- Excerpting partial XHTML using minidom
- You can use xml.dom.minidom to parse partial XHTML as long as you use a few tricks and don’t mind that getElementById doesn’t work.
- 18 more pages with the topic Python, and other related pages
More AppleScript
- Stack windows on top of each other
- If you want to stack multiple windows directly on top of each other, it’s easy to do in any well-behaved application, such as Nisus Writer Pro, Safari, Mail, and even older applications like AppleWorks 6 and Microsoft Word X.
- Getting the selected playlist in iTunes
- It took a while to figure out how to get iTunes’s selected playlist as opposed to the current playlist in AppleScript.
- Converting FileMaker to Django
- Appscript and the Django API make it easy to transfer data from Mac OS X scriptable applications into a Django-powered database.
- Play this song backwards in iTunes
- Using AppleScript and Quicktime, you can play any song backwards. Find out what Fred Schneider was saying on “Detour Thru Your Mind”.
- Create a web browser in AppleScript Studio
- AppleScript Studio is a powerful means of putting a graphic user interface onto AppleScript applications. Interface Builder lets us use any of the simple and complex controls that any other application can use.
- Seven more pages with the topic AppleScript, and other related pages
More appscript
- Converting FileMaker to Django
- Appscript and the Django API make it easy to transfer data from Mac OS X scriptable applications into a Django-powered database.
- Cleaning iTunes track information
- Python and appscript make it easy to modify iTunes track information in batches—if you’re willing to get your hands dirty on the Mac OS X command line.
- Using appscript in Python to control GUI applications
- The appscript module for Python lets you control scriptable applications on the command line without having to coordinate your command-line script with your Applescript applications.
