AppleScript

Latest

  • Lyric fetchin' lovin': how to batch fetch lyrics with GimmeSomeTune and Needle Drop

    by 
    Sang Tang
    Sang Tang
    07.14.2009

    One neat little thing about the iPod and iPhone family of devices is their ability to display lyrics -- supported by all iPod nanos as well as the iPhone/iPod touch, and iPod Classic 5th generation and higher. On the iPhone and iPod touch, lyrics show up when a song is loaded (and can be re-displayed by tapping on the screen while a song is playing); while on the iPod nano, pressing the center button several times while a song is playing will cycle you through to display lyrics. But the real issue isn't so much about displaying lyrics as much as it is obtaining them. PearLyrics was once my tried and true favorite way of getting lyrics, but it passed away some time ago.

  • Great beginner's guide to AppleScript

    by 
    Dave Caolo
    Dave Caolo
    07.08.2009

    Many years ago I started playing with AppleScript. For some reason, it failed to hold my attention, though I know you can do many cool tricks with it. Perhaps I'd still be at it if I had found an overview like the one posted at AppStorm.This well-written guide starts with the basics and builds from there. I've seen entirely too many AppleScript guides that either go from the Tell statement right to masters-level stuff or that end entirely after creating the obligatory "Hello, world!" script.Joshua, writing for AppStorm, covers variables, accessing dictionaries and walks readers through the creation of a handy Mail script. It's not comprehensive, of course, but just right as an introduciton. Check it out and get scripting.

  • iTunes 101: How to prevent podcasts from spoiling

    by 
    Sang Tang
    Sang Tang
    07.08.2009

    Like milk, podcasts will spoil if left unused for a period period of time -- at least in the mind of iTunes. iTunes will automatically unsubscribe from a podcast that hasn't been listened to within the last 5 updates, and more than 5 days have passed since an episode was played.The rationale, as Apple states in the documentation for podcast providers, is to "minimize unnecessary bandwidth costs for both the user and the podcaster," as well as making it more likely that episode downloads align with the actual plays of the episode.But I like the option of being current on all my podcasts, as well as being selective about which episode(s) I want to listen to. And being the rebel that I am -- using a two button mouse in 2001 while everyone else was still control-clicking -- this means that I will sometimes not listen to a podcast within these set parameters. In the past, iTunes would keep me in check by forcing me to manually click on the exclamation mark next to each podcast to resume updating the podcast. Needless to say, this became a chore after the 10th click. You can also select all your podcasts, right-click and choose "Update Podcast" to force a global update, but why do three steps when AppleScript is there to reduce those to one?iTunes will keep me in check no longer, as Doug Adams (of Doug's Scripts fame) provides a solution for this issue with his Update Expired Podcasts v2.0 AppleScript -- which batch updates each of your podcasts. You could even set up an iCal alarm that runs the script every day to force a fresh set of podcasts.Update Expired Podcasts v2.0 (download link) is donationware, and is available for download at Doug's Applescripts for iTunes site (link). It's finger clickin' good.

  • Meerkat 1.2, 100% more AppleScript support

    by 
    Brett Terpstra
    Brett Terpstra
    05.27.2009

    If you work from non-secure networks (coffeehouses, airports, hotels, etc.), or if you've ever wanted to bypass a firewall (YouTube or TUAW blocked at work?) you may be familiar with SSH tunneling. It's come up more than once here on TUAW. It allows you to conduct your Internet business through a secure proxy and makes the process transparent (once you set it up, you don't have to think about it). It's typically handled via a shell command, but some GUI-based programs can make life a lot easier -- both for the less technically-inclined, and for those who want to handle multiple tunnels and automation. Enter Meerkat, the SSH tunnel tool with the friendly face. I mentioned Meerkat about a year ago, and apparently things have been busy at the Code Sorcery Workshop since that release. The latest version of Meerkat -- version 1.2 -- sports an array of new features, from AppleScript support to a command line utility, as well as improvements to existing features like Bonjour sharing and the tunnel editing interface. I've been using the previous version for quite some time now, and I can say that this version adds some great features to an already great application. AppleScript support means automation, and Meerkat plays well with location managers like NetworkLocation (a plugin is available on the Meerkat page), or any location manager which can run AppleScripts or shell commands. With such a setup, you can have your system automatically detect a change in networks and set up specific tunnels depending on your location. I won't go into the details of location managers right now, but it's something to look into for laptop owners on-the-move. Additional features, including Application Triggers, Bonjour support and automatic reconnect for dropped tunnels all make Meerkat a valuable tool. At a current price of $19.95US, Meerkat provides features for a spectrum of users, from the Tunnel Setup Assistant for newbies, to advanced automation possibilities for veteran SSH'ers. I'd be negligent if I didn't mention at least one similar app in the freeware realm: SSHTunnel is a nice, easy-to-use GUI for setting up and managing tunnels. It lacks some of the automation and integration capabilities, but is a definite must-see if you're not ready to fork out for something more full-featured. A trial of Meerkat is available for download, and a license can be purchased for $19.95US.

  • AppleScript: Exploring the power of Folder Actions, part III

    by 
    Cory Bohon
    Cory Bohon
    03.26.2009

    So far in this AppleScript feature we've covered what folder actions are and how to create them. In this AppleScript post, I'm going to tell you how to create your own custom scripts and add them to your folder actions list. If you work with file permissions a lot, then you know how crazy it can get when you need to change a ton of files to their correct permission types. With this AppleScript folder action, you can easily change the permissions just by dragging and dropping files in their correct folder. Creating the Script To get started, we'll open the Script Editor (located in /Applications/Utilities). Once you have the editor opened, copy/paste the following script: on adding folder items to this_folder after receiving added_items tell application "Finder" set fold_name to the name of this_folder try repeat with i from 1 to number of items in added_items set new_item to item i of added_items set the item_path to the quoted form of the POSIX path of new_item do shell script ("/bin/chmod -R +r " & item_path) end repeat end try end tellend adding folder items toThis script will change the dropped files to a permission of "0644" meaning that everyone can read the file. For information about chmod and command line permissions strings, visit the Wikipedia page. Continue reading to learn more about this AppleScript and folder actions.

  • AppleScript: Exploring the power of Folder Actions, part II

    by 
    Cory Bohon
    Cory Bohon
    02.23.2009

    In the last AppleScript post, I mentioned some of the useful ways to create Folder Actions, and showed you how to use one of the built-in scripts to perform a pretty useful action. In this AppleScript post, we'll dive into the built-in scripts in more detail, and I will tell you how each of them works. Once you create a new folder action (as we did in the last tutorial), you will have a pop-up dialog asking if you would like to attach an Apple-created script. There should be around 13 preinstalled on your Mac. Now let's go through each of them, and see what they will do when attached: Add-new item alert.scpt - This included script, which we covered in the last post, allows you to get a pop-up dialog upon dropping files in the attached folder. So, if you were to drop file x into the folder, a dialog would display a message that file x was just dropped in there. This script is great for networked folders, as you get a dialog when someone drops something in there. Close-close sub-folders.scpt - This script will, when a file is dropped in the attached folder, close all opened Finder windows associated with that folder and subfolders. So, if you have that folder opened, or another subfolder within that folder, when you drop a file into it the script will close those opened Finder windows. You can use this script to tidy up your screen. Convert-PostScript to PDF.scpt - If you have a PostScript file type (i.e. eps or ps files), then you can enable this folder action. When you drop a PostScript file on it there will be two folders created, one called "Original" and the other called "PDF." This folder action will take those PS files and turn them into PDFs for your instant viewing pleasure. You can use it in your workflow to easily convert from PS to PDF. Read on to learn about even more built-in folder action scripts.

  • AppleScript: Exploring the power of Folder Actions, part I

    by 
    Cory Bohon
    Cory Bohon
    02.16.2009

    Welcome to Part I of this mini AppleScript feature on creating useful folder actions. We'll have more posts on this topic coming up, but for now, let's introduce what a folder action is. Have you ever wanted to just drop a file into a folder and have something magically happen? Say, have a file printed, whisked to a remote site via FTP, or perhaps have an image be automatically flipped from horizontal to vertical? With Mac OS X's built-in folder actions, you can easily do this with a simple drag and drop. Creating the folder First, let's talk about how we can enable these "magical folders" that perform actions on files dropped within them. For this example, I'll show you how to make a folder on your desktop that, when a file gets dropped into it, will display a dialog letting your know that the file was placed there.

  • Revisiting the randomized signature AppleScript, now with API goodness

    by 
    Brett Terpstra
    Brett Terpstra
    02.10.2009

    When I shared an AppleScript last week which created randomized signatures using TextExpander, I promised to revisit it when the iheartquotes.com API started working again. It's working right now, but it seems to go up and down; check this link before you try the script and make sure you get a quote, not an error message. As before, when used with a TextExpander snippet set to the AppleScript type, this script will provide a random quote, this time pulling it from the Internet rather than our own list. The script is essentially the same, so I'm only going to explain the part which changed; visit the previous article for a rundown on the rest: set _date to do shell script ¬ "date +'Sent on %A, %b %d at %l:%M %p'|tr -s ' '" set _quote to "" try set _quote to do shell script "curl -s \\ 'http://www.iheartquotes.com/api/v1/random?source=macintosh&max_lines=4'" set {astid, AppleScript's text item delimiters} ¬ to {AppleScript's text item delimiters, return} set _quote to paragraphs 1 through -3 of _quote as string set AppleScript's text item delimiters to astid end try set _out to " -Brett " & _date & " ________________________________ Brett Terpstra | myemailaddress@mywebsite.com The Unofficial Apple Weblog | http://www.tuaw.com " & _quote return _out The curl call Here's the part which makes this more interesting than it was before: set _quote to do shell script "curl -s \\ 'http://www.iheartquotes.com/api/v1/random?source=macintosh&max_lines=4'" First off, that really should be all one line, but is split here for formatting purposes. You can remove the double backslash (\\) and merge the lines together if you like. What this does is use AppleScript's ability to run shell scripts (Unix commands) to make a curl call to retrieve a response from the iheartquotes API. Note the "try" statement surrounding that section; it will just return our regular signature without the quote if anything goes wrong. If it gets a response, it stores it in a variable (_quote) and then trims off the last line, like this: set {astid, AppleScript's text item delimiters} ¬ to {AppleScript's text item delimiters, return} set _quote to paragraphs 1 through -3 of _quote as string set AppleScript's text item delimiters to astid The first two lines (actually one line) are shorthand for setting "AppleScript's text item delimiters" -- the character that AppleScript uses to separate text items in a block of text -- to the return character and store the current text item delimiter in a variable so we can restore it with the last line. Using the paragraphs command, which automatically uses the return key to separate paragraphs, we turn the quote into a list of paragraphs, starting with the first and ending with the third from last. This is because the last two "paragraphs" are always an empty line and a permalink (even if you use the API's parameters to turn off the permalink). The last part of that line, "as string", is where the text item delimiters come into play, putting the list items back together with a return after each one, reconstructing the original formatting. Note: You could do the same thing by adding |sed -n '$!p' to the end of the do shell script line, right before the last double quote. I suppose you might as well, as long as you're dipping out to the shell anyway ... From there it's the same as before, just building a final output string from the pieces we've created. This method provides a much wider variety of randomized signatures than constructing your own list by making use of a small section of the wide array of data on the interwebs. The use of curl in an AppleScript can open a lot of possibilities, such as posting to Twitter in various ways. or shortening urls on the fly. Have fun.

  • Random Signatures with TextExpander and AppleScript

    by 
    Brett Terpstra
    Brett Terpstra
    02.02.2009

    TextExpander, a $29.95US utility which inserts snippets of text or images when you type a preset string of characters, has long been a TUAW favorite. I only recently learned that it can run AppleScripts within a snippet, which opened up a world of fun for me. Here's a quick script demonstrating how AppleScript can be used to randomize quotes within your email signature. Create a new TextExpander snippet and set the content type to "AppleScript." Copy and paste the code that follows into the snippet content box. I'll run through what it does in at the end. Read on for the script!

  • AppleScript 1-2-3 now available from Peachpit Press

    by 
    Steve Sande
    Steve Sande
    12.24.2008

    Mac users rejoice! Santa brought just what you wanted, a new book about AppleScript by the two of the top wizards of the Mac automation world.Apple's Product Manager for Automation, Sol Soghoian, and Bill Cheeseman, who is a noted developer in his own right, have announced the publication of AppleScript 1-2-3 by Peachpit Press. This book guides AppleScript newbies through an easy and enjoyable process of understanding how to use the Mac's automation language. Soghoian and Cheeseman based the book on ideas and scripts that have been used at hands-on seminars taught at Macworld Expo. While the book can take someone with no prior knowledge of programming or AppleScript and turn them into a confident Mac automator, experienced scripters will find a lot to like about AppleScript 1-2-3 as well. The authors have made a copy of the first chapter available on the Apple AppleScript website. During Macworld Expo, the Peachpit website will feature a "tip of the day" from the book. The book will be available at the Peachpit booth as well (#812).The book is available for pre-order now (US$44.99) through Peachpit, and will start appearing in bookstores in January. There's also an Adobe Reader version of the text that is available now (US$35.99) for download.

  • Mac Automation: Rename multiple files efficiently

    by 
    Cory Bohon
    Cory Bohon
    11.11.2008

    With Automator, you can easily streamline common tasks. If you work with many files (i.e. pictures), then you know how easy it is to lose track because of incorrectly named files. With this Automator workflow, you'll never lose your place (or a file) again. Building the Workflow To create this workflow, simply add the following Automator actions (in the same order): Get Specified Finder Items Rename Finder Items When you add the "Rename Finder Items" action to your workflow, Automator will ask if you want to copy the files so you don't mess with the originals. Choose "Don't Add." Configuring the Workflow In the "Rename Finder Items" action, you have almost unlimited choices for renaming schemes. To get started, select a scheme from the first drop-down box. You can choose from: Add Date or time, Add Text, Change Case, Make Sequential, Replace Text, Name Single Item. Once you select your renaming scheme, choose the options you want based on the scheme. For instance, if you wanted the "Make Sequential" scheme, you could choose to use existing naming, or create a new name. You can also select options for where to place the numbers, which number to start counting from, and how to separate the number from the rest of the text. Running the Workflow Once you have your naming scheme figured out, it's time to run the workflow, and have Automator do the heavy-lifting. Drag and drop the files you want renamed onto the "Get Specified Finder Items" workflow. They will be added to the list of files to be renamed. You can then click the "Run" button in the top-right corner of the window. Your original files will be renamed, leaving you with perfectly renamed files. You can now save your workflow. Want more Mac Automation or AppleScript tutorials? Visit TUAW's Mac Automation and AppleScript sections.

  • The ever-extensible Evernote

    by 
    Brett Terpstra
    Brett Terpstra
    10.20.2008

    Evernote, a versatile (and oft-mentioned) note-taking application for Mac and iPhone (as well as Windows and other mobile platforms), has recently opened up a Service API. This comes as an intriguing extension to the basic AppleScript support found in the 1.1.5 release, and opens up the possibility of creating homegrown interfaces ranging from simple calendar/todo managers to "thick" clients which can manipulate the entire collection of Evernote data. The AppleScript library itself is quite useful, albeit slightly limiting. You can retrieve lists of notes based on searches, create new notebooks and notes from a variety of sources, and obtain properties for the various elements of Evernote. The most interesting feature of the AppleScript library is the import/export automation capability. You can export (in well-formed XML) entire notebooks, or notes from a list (such as one generated by a search). These can be transported automatically by whatever means work best for your purposes, and then imported on the other end. This, to me, is primarily interesting because it allows for "local" synchronization of large libraries without using up online quotas. It's also ideal for automatic backup of your notes, among other potential applications: a recent MacOSXHints tip shows a means of adding notes to Evernote via Quicksilver, complete with notebook, title and tagging syntax. Open the Evernote dictionary in Script Editor for the full set of definitions. The AppleScript library lacks the ability to add tags to existing notes, move notes or delete notes and notebooks. These functions can, however, be found in the Service API. I'm waiting on an API key today, but I'm looking forward to exploring the possibilities for both desktop and web applications. Libraries for the API are available in Java, Perl, PHP, Python and Ruby -- along with sample code and documentation -- at the API overview page. The last thing I'll mention is the query syntax, which can be of as much use in the Evernote search bar as it is in an AppleScript or API call. I hadn't fully realized the extent of the search grammar until I read the API documentation. For Evernote users who haven't explored this, it's a very effective way to build searches quickly without a lot of token-clicking. You can start with the basic tag syntax: tag:"tuaw", which will find every note tagged with "tuaw." Prefix it with a minus sign (-tag:"tuaw") to ignore any result with the "tuaw" tag. Combine multiple search parameters for boolean searches; the default search is "all", requiring the results to match every parameter in the string (AND), but you can prefix the query with any: to make it an OR search. Other possible parameters include created: and updated: (which respond to some natural language dates as well as a compact profile of ISO 8601), intitle: (search only in the titles of notes), as well as terms for narrowing to a specific notebook or querying just about any attribute of a note (latitude, longitude, altitude, author, source, etc.). See section C of the API docs for a full description of the search grammar. It's great to see such a useful application continuing to expand itself and allow for third-party interaction. If you're interested in developing around Evernote, or just playing with the possibilities, stop by the developer page and take a look around.

  • Export your Yojimbo database to a Tiddlywiki

    by 
    Giles Turnbull
    Giles Turnbull
    08.06.2008

    You've got all your iStuff inside Yojimbo (hands up who loves Yojimbo and I'll count, starting with me), but for some reason you need to get it on to another computer, perhaps one running a different OS. What to do? This AppleScript takes your entire Yojimbo library (well, everything except the PDFs) and exports it to a Tiddlywiki that you can carry around and view on pretty much any computer. I say "any computer" but iPhone users shouldn't get too excited just yet. Apparently, the standard Tiddlywiki doesn't display that well on an iPhone. But, ooh, wait: what do we have here? Thanks to Jon for the tip.

  • AppleScript: Creating To-Dos in iCal

    by 
    Cory Bohon
    Cory Bohon
    08.05.2008

    Recently, a friend asked me to create an AppleScript that would allow him to automate To-Dos with a Mail.app mail rule. I immediately rose to the occasion because this was a cool idea: Mail.app could run the script when you get an ebill, for instance, for your car payment. The script would then create an iCal To-Do for "Pay your car payment, now!" The scriptset theSumm to "Pay My Bill Soon!"set dueDate to (current date) + 10 * daysset theUrl to "http://www.paymybillexample.com"set thepriority to 1tell application "iCal" make todo at end of events of (item 1 of every calendar) with properties {summary:theSumm, due date:dueDate, url:theUrl, priority:thepriority}end tell Customizing the scriptTo customize the To-Do's title, fill in the text you want, within the parenthesis on line 1. To Change the due date, change the "10" in line 2 to the number of days until it is due. If you want to change to weeks or months, use the appropriate wordage instead of "days" at the end of line 2. To change the URL, paste a URL in the parenthesis on line 3. By default, the script will set the newly created To-Do to have a priority of 1, however, you can change this to your priority preference.Continue reading to learn how to integrate the To-Dos with a Mail.app mail rule.

  • AppleScript: Taking screenshots

    by 
    Cory Bohon
    Cory Bohon
    07.07.2008

    Last week, Dave mentioned that you can change the file type used system-wide for screenshots. However, some people are afraid of using Terminal.app to muck around with their Mac. In this week's AppleScript article, I am going to show you how to take screenshots and change their file type using an AppleScript.The AppleScriptproperty N : 0set N to N + 1set picPath to ((POSIX path of (path to desktop)) & "Picture_" & N & ".png") as stringdo shell script "screencapture -tjpg " & quoted form of picPathUsing the AppleScriptOpen the ScriptEditor (/Applications/AppleScript/ScriptEditor.app). Copy/paste the AppleScript into the script edtitor and click the run button at the top. You will hear the camera shutter sound and a picture will be taken and saved to your desktop. This script comes in handy when you want to take a screenshot in a different format. To do this, just change the ".png" file type to whatever you might want (say, .jpg, .tiff, etc.). When you re-run the script, the new file type will be associated with the capture image. Continue reading to learn how to save this script.

  • Simplify media transcription with hotkeys and AppleScript

    by 
    Brett Terpstra
    Brett Terpstra
    06.26.2008

    I've found myself transcribing different types of media lately; primarily recorded Skype conversations and footage from interviews. I do a lot of work in Scrivener, an application so enjoyable that it makes me want to write a lot more than I do. Scrivener allows for a split pane editor with a QuickTime media file loaded in one pane, and your current document in the other. While you type you can hit Shift-Space to start and stop the media. I loved it, but I wanted to take it to another level. There are applications specifically designed for this, but why not have a system-wide, works-with-anything solution? Find out how I did it after the jump.

  • AppleScript: Integrating shell scripts

    by 
    Cory Bohon
    Cory Bohon
    06.23.2008

    We've talked about AppleScript how-tos before. AppleScript is fun and all, but what if you already know how to write shell scripts? Well, did you know that by integrating shells scripts into AppleScript, you can create simple applications that do useful things? It's true, and I am going to show you how. Continue reading to learn how to integrate shell scripts into AppleScripts.

  • TUAW Tip: Setting your clock automatically after using Boot Camp

    by 
    Robert Palmer
    Robert Palmer
    06.03.2008

    I use Boot Camp pretty regularly, and one thing that always annoyed me about booting back into the world of the living the Mac was that my clock was always eight hours behind (I live in the Pacific time zone). Windows likes to set the system clock to my local time of GMT –8. Mac OS X, on the other hand, likes to keep the hardware clock at GMT, and set it "softly" using the operating system software. There are some hairy registry fixes for the Windows behavior, but they're unsupported. While manually setting my clock back for the eleventy billionth time, I noticed that just opening and closing the Date & Time preference pane sets the clock automatically. Of course, I had to be connected to the Internet, and have the "set date & time automatically" checkbox selected. Sensing an opportunity to make my life easier, I wrote myself an AppleScript that simply opens the Date & Time preference pane, leaves it open for a few seconds, and then closes it. I saved it as an application, and set it to run at startup. That way, by the time my computer is finished booting, the clock is right, and I didn't have to even think about it. After the jump, some code and instructions on how to do this yourself.

  • Applescript to arrange your desktop

    by 
    Dave Caolo
    Dave Caolo
    05.22.2008

    Here's a very cool tip we first saw at Lifehacker. Jeff Kelley is a MacBook Pro user who, like many others, connects it to several displays, depending on context and the task at hand. If you've done this, you may be familiar with the same irritation that has bothered Jeff. Namely, application windows re-sizing themselves across displays. The difference between Jeff and the rest of us is that he did something about it.Here is a great AppleScript that notices his screen resolution and sizes his application windows according to his likes. Now, Mail, iCal and so on will appear just where they ought to. Very cool!

  • Mac Automation: Get remote screenshots via Mail

    by 
    Cory Bohon
    Cory Bohon
    05.19.2008

    I've talked about getting your Mac to shutdown via an e-mail (or even take a picture from your iSight and e-mail it back to you), but I have received some comments and e-mails about using this script to send a snap of your computer screen when you want to "check up." So, in this Automator tutorial, I am going to show how to get a screenshot of your Mac no matter where you are -- via e-mail.Continue reading to learn how to generate screenshots via Mail.