Published on
July 4, 2010 in
General.
I’ve done a fair amount of applescript work (mostly automation & UI scripting related projects) over the last couple months and – although very frustrating – applescript can allow you to achieve some incredible automation tasks. I’ve compiled a disjointed lists of tips, tricks, and source code that some trying to wade through applescript (specifically ui scripting which can be especially tricky) might find useful.
Enable Access for Assistive Devices
tell application "System Events"
set UI elements enabled to true
end tell
When “set value of text field” Won’t Work
set value of attribute "AXValue" of text field 1 to "String"
How To Iterate Through Rows in a Table
repeat with r in rows of table 1 of window 1
log r
end repeat
Retrieve Every UI Element Available in a Window
tell application "System Events"
tell process "Process Name"
set visible to true
return every UI element of front window
return name of every UI element of front window
end tell
end tell
Get a List of the Children of a UI Element
return value of attribute "AXChildren" of UI element 1
Create / Update / Connect Network Preferences VPN Services
Although since OS X 10.5 we have been given better applescript access to network preference settings, it still isn’t possible to create / update services / interfaces through applescript. With some tricky UI scripting and the help of the UI Element Inspector (or the advanced UI Browser) it is possible to create and update VPN service information. I also wrote a couple functions that allow you to check the existence of a VPN service and the connection status. You can check out the source code here. Note that although the code is VPN service specific it wouldn’t be terribly hard to modify the code for use in automating the creation of aiport, ethernet, etc services.
Take a Screenshot of a SWF
This is a bit more complex that one would expect. Because the Flash Player isn’t built using cocoa it doesn’t support alot of native applescript methods and getting a screenshot of the actual content (not containing the title bar!) of the swf is actually pretty challenging. The script will take a screenshot of only the content of the actual swf. This is useful if you have a flash app that has loadable swf components that the user should be able to preview through a thumbnail. Coupling the script with the following bash script allows you to easily generate thumbnails for all the swfs in the specified directory.
#!/bin/bash
function normalize_path() {
eval "NORMALIZED_PATH=$1"
NORMALIZED_PATH=`php -r "echo realpath('$NORMALIZED_PATH');"`
}
find ../path/to/swfdirectory -name "*.swf" | while read line; do
# remove the relative reference
normalize_path "$line"
line=$NORMALIZED_PATH
# open the flas
open -a "Flash Player" "$line"
sleep 1
thumbnailPath=${line/.swf/.jpg}
osascript slide_preview.scpt "$thumbnailPath"
killall "Flash Player"
done
exit 0
Other Applescript Code Snippets:
Helpful Applescript Articles
Published on
June 27, 2010 in
General.
It is often hard for me to find the time to actually finish a blog post for this site, I have many many drafts that are about 70% complete but as of now I can’t find the time to finish them and get them out onto this blog.
However, I’ve still been trying to push as much work as I can out into the public realm. Here are some sides that I frequently post code / projects / findings onto:
Hopefully you will find some of the code / ideas I post on those sites useful.
As an aside, I’ve been fascinated with Twitter: there is no ‘right way’ to use Twitter. Facebook is pretty straightforward – connect and stay and in touch with others. Twitter is a generic searchable database accessible from anywhere with easy ways to create relationships between different pieces of data and connect with the larger web as a whole. I use my Twitter account mainly as a bookmarking service; I find the traditional bookmarking model to be very lacking, I’m surprised Apple / Google / Startup will reinvent the wheel. It will be interesting to see what these different massive social sites end up turning into.
Published on
May 30, 2009 in
General.
I love MooTools. I’ve been using it before the 1.2 days; it has been great watching how much it has matured. One of the best things about MooTools is the amount of components that have been written for it: Videobox, SlimBox, and TextBoxList just to name a few. However, the switch from 1.1 to 1.2 broke alot of existing functionality and with that broke alot of the existing components.
Just the other day I found just the component I was looking for: Videobox. The examples on the site looked great, but it didn’t work with the newest version of MooTools. I spent some time converting the animation code over to the new 1.2 syntax and fixing some other random bugs, you can grab the fixed version here. I emailed the developer with the fixes, so hopefully he will post it on the project page soon.
Published on
January 6, 2009 in
General.
I’ve been meaning to finally update the design & content on this site, and finally I’ve gotten around to finishing up the design and updating the entire backend. I’ve updated wordpress and I’m still working out some issues with some plugins I was using; but for the most part everything is updated. There are some minor things I’ll be changing around over the next couple days but I’m hoping I’ll be able to jump right into posting some of new things I’ve been wanting to share over the last couple months.
Published on
December 29, 2008 in
General.
I’m finally, after almost four years, redesigning and refreshing this site. I’ve definitely neglected this site over the last couple years and have been devoting alot of my time to other endeavors in and out of the programming world. However I’m ready to reconvene and start posting regularly on this site again. I have alot of content I want to post that I’ve developed over the last year or so. I have updates to all my applications (both open-source and shareware) that I will post at sometime in the future as well as a new application that I will hopefully release within the coming months. I’m excited, and I hope you are too!
Published on
July 24, 2008 in
General.
Yesterday I was greatly distraught when my MacBook Pro’s superdrive would not accept blank DVD-Rs. When I inserted a blank DVD-R it spun around for a bit, sped up, slowed down, stopped, then spit it back out at me with no error message. It read DVDs, burned CDs, and read CDs fine; but I could not get it to accept a blank DVD-R! I searched around and found information about the MacBook superdrive update which killed alot of people’s optical drives. I couldn’t remember if i installed the update or not, so I was fairly worried because I did not want to drop $400 to fix something which an Apple update broke.
I tried a bunch of tricks to try to get my beloved superdrive to work, but to no avail. Finally while searching around on google someone suggested to get a CD cleaner. I went to Staples and picked one up for $10, put it into my optical drive, and bam it burns DVD-Rs again! I’m guessing the firmware update made the optical drive more sensitive to dust. If your having trouble with your MacBook’s optical drive I suggest grabbing one of these CD drive cleaners and trying your luck before resorting to bringing your computer back to the Apple store.