Q:Any idea how to get the bootcamp script to work in 10.8?
I’m not running Bootcamp myself anymore, but I don’t see that anything has changed.
Did you remember to enable UI scripting (System Preferences / Universal Access)?
If it still doesn’t work, open up Console.app before running the script and tell me what error messages you get.
Encrypt and Decrypt text through AppleScript
If you want an easy way to encrypt and decrypt text using a passphrase, this may be something for you. I’ve written a Java command line tool using Jasypt (an open source library for encryption) that you can call from your AppleScripts.
- Download the Jar file.
- Call it from your AppleScript using a “do shell script” command like this:
-- Encrypt text
set textToEncrypt to quoted form of "Wanna know a secret?"
set passphrase to quoted form of "OurSecretPhrase"
set encryptCommand to "/usr/bin/java -jar /path/to/TextCrypt.jar encrypt " & textToEncrypt & " " & passphrase
set encryptedText to do shell script encryptCommand
-- Decrypt text set
textToDecrypt to "Some∞™¶©©«‹Gibberish"
set passphrase to "OurSecretPhrase"
set decryptCommand to "/usr/bin/java -jar /path/to/TextCrypt.jar decrypt " & textToDecrypt & " " & passphrase
set decryptedText to do shell script encryptCommand
To make it extra convenient, you can use Automator to set up services to encrypt and decrypt with just one keystroke. If you need help setting up a Service workflow in Automator, leave a comment and let me know.
Create a dynamic “Today In History” wallpaper with AppleScript.
Okay, this one is a little more advanced than the other scripts I’ve posted and it requires the command line tool ImageMagick (free, open source) to be installed on your system.
Here’s what it does:
- Use curl to download the html source of this webpage.
- Use AppleScript’s text item delimiters to extract the text entries.
- Use the “strip” handler to remove html tags from the extracted text.
- Use the “ordinalSuffix” handler to format the date.
- Pass the collected text to ImageMagick to produce a jpeg with the text.
- Ask Finder to set the created image as the desktop wallpaper.
I’ve created a Gist with the entire code which you can copypasta into the AppleScript Editor, but you need to manually edit some portions of the script to fit your own system. Read the comments in the start of the script for detailed instructions. If you still can’t make it work, leave a comment here and I’ll see if I can help you.
How to Embed Source Code In Tumblr Blog Posts Using GitHub Gist
I just found this little gem for those of you who want to put source code in your blog posts. I will surely use it from now on.
Being a developer, we often write code related blog posts and often struggle with its’ formatting. Here’s what I need:
- Render code with good formatting
- Allow copy and paste
- Allow me to manage changes to the code
It’s been around for a while now, but Gist deserves to be the source view provider on all blogs. This post details how to get that to work on Tumblr in less than 5 minutes.
Programming is the art of figuring out what you want so precisely that even a machine can do it.
Upload images to imgur.com
It’s been a long time since my last post. Since I started school again, I’ve been focusing mainly on Java and iPhone development. But… I’m back with a new script that I think will be useful to a lot of people: Right click an image file and select “Upload to imgur”. Once the image(s) have been uploaded, your default browser will open a tab for each image.
If you don’t know imgur, it’s a free image hosting service where users can upload images anonymously and get a link to share with other people.
It’s written in AppleScript, but it’s wrapped inside an Automator workflow that has been saved as a Service.
In stead of writing out all the code here, I’ll just give you a link to the finished .workflow file in my dropbox (see below). If you want to check out the script or make edits, you can just open the file in Automator.
If you want to use the service, all you have to do is extract the .zip and copy the .workflow file to ~/Library/Services (that’s your user library, not the system library).
You’re free to modify and distribute the workflow in any way you want (non-profit, with attribution and link back to this page).
EDIT: If you can’t find your user’s library folder it’s because Apple has set it to hidden in Lion. To unhide it permanently, execute this command in Terminal.app: chflags nohidden ~/Library
If you just want to access the folder once and leave it hidden, select Go in the Finder’s menu bar, select Go to folder, and write ~/Library
Thanks to Reddit for making me aware of the omission.
Imgur’s API allows you to upload images into a personal account in stead of anonymously. If anyone wants this feature, leave a comment and I’ll write up some instructions on how to edit the script.
EDIT 3: I hope none of you got your hopes up about EDIT 2 because that process was a little more complicated than I had thought :(
Decimal to Binary Converter
This week I’ve started my computer science studies. Some of the exercises in one of the work books involved converting between decimal and binary numbers. Converting from binary to decimal is easy to do in the head, which I’ll show you, but I need pencil and paper to go the other way. I asked a teacher if he knew any tricks, and he challenged me to come up with an algorithm for it.
So here’s how you mentally convert from binary to decimal:
- Read the binary number from left to right and start from the first number (always a 1).
- Start your mental count, you begin with 1.
- Move one digit to the right.
- If it’s a zero, multiply your count by 2.
- If it’s a one, multiply your count by 2 and add 1.
- Repeat with all the digits and at the end your mental count will be the decimal value.
The AppleScript for converting decimal to binary is after the break.
Using AppleScript to return a random quote
Here’s an easy way to put a random quote anywhere you like.
This script looks through a text file containing hundreds of quotes, then it selects a random quote and returns it. Here’s a link to the text file I use. I grabbed it from this site where you can find several other collections of quotes in plain text files. However, if you choose to use a different quote collection, you will have to change the text item delimiters in the script to fit your text file.
In any case you should edit the first line of the script and enter your own path to the text file.
Here’s an example of what the script outputs:
murphy's tenth law:
mother nature is a bitch.
I’ve chosen to use TextExpander to launch this script, so I just have to enter ‘quote’ with an extra q in front of it, and in pops a quote.
The script is after the break
AppleScript code formatting fixed.
Since I started writing this blog I’ve been trying to find a way to have the actual AppleScript code displayed as plain text so that users could just copy-paste the script into their editor.
Well, I finally figured out how to do it and I’ve updated all my previous posts. In case you’re interested, here’s how I did it:
- Click the “html” button in the post editor.
- Put the entire script inside one single paragraph (<p> </p>) with each line ending with <br>.
- Wrap the paragraph in a <code> </code> tag.
Another small victory :-)