AppleScript

Latest

  • Tips for Troubleshooting Automator Workflows

    by 
    Ben Waldie
    Ben Waldie
    03.04.2013

    Automator's great for streamlining time consuming and repetitive tasks on your Mac. It's easy. Just launch it, find a few actions, and string them together to form a workflow. Then, run your workflow anytime you want to perform that series of tasks again. What happens if your workflow doesn't run as you expect, though? Finding and solving problems in Automator is often easier said than done. Suddenly, the simple tool that's supposed to make your life easier has become a real pain in the neck. This week's post covers some things you can do to troubleshoot a finicky Automator workflow, track down the problem, and hopefully solve it, so you can get back to work. 1. Run Saved Workflows in Automator Automator workflows are saved and run in a variety of ways - as apps, iCal alarms, print plugins, and more. When a saved workflow encounters a problem, however, it may be next to impossible to figure out what went wrong. This is because saved workflows don't really include any diagnostic tools. In some cases, the workflow may even fail silently, without alerting you that something is wrong. Your only indication of a problem may be a lack of the end result you were expecting. Not very helpful, especially in a longer multi-action workflow. When you encounter a problem with a saved workflow, your best bet is to open up the workflow in Automator, and try running it there. By doing so, you'll gain access to some of the techniques described below. 2. Fake Workflow Input When you run a workflow app or plugin within Automator, you may see an alert indicating that the workflow will not receive input. An Automator Input Alert for a Text Service Workflow This is because, often, saved Automator workflows expect input for processing. For example, a workflow app may expect dropped files or folders as input, a service workflow may expect text as input, or a print plugin may expect PDF files from the print system. In any case, just dismiss the alert and add an action to the beginning of the workflow to retrieve the required type of input. If your workflow processes files, for example, add a Get Specified Finder Items action. If your workflow processes text, add a Get Specified Text action. Whatever you add, just be sure to remove it once you're finished troubleshooting. Get Specified Text at the Beginning of a Text Service Workflow 3. Check Action Results Automator works by passing information to actions for processing. Most actions perform a very specific function. As such, they accept specific types of information as input. And, they produce different types of output. The New TextEdit Document action, for example, wants text as input. It then adds this text to a new TextEdit document, and passes the document as output for further processing. Often, when a workflow fails or produces an undesired result, it's because actions aren't receiving or producing the expected types of information. To diagnose this problem, click the Results button beneath each action in your workflow. Then, when you run the workflow, you can see exactly what information is being passed from action to action. Suppose, for example, I have a workflow that should take the contents of a text file and add it to a new TextEdit document. I may try creating my workflow with the following actions: Get Specified Finder Items - Configured to get a text file Filter Paragraphs - Configured to look for non-empty paragraphs New TextEdit Document All the actions appear to link up properly, and the workflow may even run without an error. But, the result is not what I want. Rather than the content of the text file being added to the new TextEdit document, the path of the document is added. A Misbehaving Text Workflow An Undesired Workflow Result By displaying the result area of each action in the workflow, I can see that a file path was passed to the Filter Paragraphs action as input. I can also see that the same file path was output by the action, rather than the paragraphs I was expecting. This tells me that there's something wrong with the Filter Paragraphs action. Action Results Indicate Potential Problems Checking the action's description area provides additional clues. It tells me the action expects text as input, not files. Action Descriptions Specify Input and Output Types So, in this case, the fix is to insert an action that outputs text, rather than files, before the Filter Paragraphs action. NOTE: Surprisingly, Automator doesn't include an action for reading text from a file. There are third-party actions available that can do this. Or, as a workaround, you can try using the Combine Text Files action, which receives one or more files as input and outputs their text content. 4. Check Automator's Log Checking the results of an action doesn't always tell you what went wrong. You may glean a little more information by consulting Automator's log area. Press Command+Option+L or choose View > Log to display it. When you run a workflow, the log area tells you which actions ran, and often indicates problems that were encountered along the way, such as an action that wasn't supplied with the appropriate type of input. Automator's Log Area Indicates Successes and Failures Sometimes, the log tells you that information was converted from one type to another. This is because, in some cases, Automator tries to make incompatible actions work together. This doesn't always work, however, and can result in an error. So, be on the lookout for failed conversions. 5. Step Through Workflows Running a workflow and checking action results is great, but it's even more useful to check the results of each step of your workflow as it happens. You can do this by stepping through the workflow step by step. Click the Step button in the workflow's toolbar or select Workflow > Step from the menu bar. Automator's Step Button The above techniques may not resolve every problem you encounter with Automator, but they will certainly help you to more easily identify solutions for some. Happy Scripting!

  • AppleScript Productivity > Create OmniFocus Followups from Contacts

    by 
    Ben Waldie
    Ben Waldie
    02.25.2013

    As an OmniFocus for Mac user, it's important that I can quickly create tasks at any time, in any app. OmniFocus makes this pretty easy, by providing integration with OS X Mail, a keyboard shortcut for clipping content in apps such as Safari, a system-wide Quick Entry window and a Services menu item. One feature OmniFocus lacks, however, is direct integration with the Contacts app. Suppose I am in Contacts, for example, and I need to schedule a followup phone call or email to one of my clients? Sure, I could bring up the Quick Entry window and enter the task, but I want something a bit more streamlined. I can accomplish just what I need by writing some custom AppleScripts. The following two examples demonstrate how to write AppleScript-based plug-ins for the Contacts app, which add OmniFocus followup options right into the email and phone number popup menus of your contacts. Note: If you have any trouble following along, you can download both of the scripts outlined in this post here. Creating the Email Followup Script Plug-In 1. Quit the Contacts app. 2. Launch AppleScript Editor in /Applications/Utilities and create a new script document. 3. Insert the following code: 4. Save it as a script named Contacts > Email Follow Up with OmniFocus.scpt into the ~/Library/Address Book Plug-Ins folder in your home directory. If this folder doesn't already exist, go ahead and create it. Saving the Script into the Address Book Plug-Ins folder The Address Book Plug-Ins folder in ~/Library Creating an OmniFocus Email Followup Task To give your new plug-in a try, launch the Contacts app and go to a contact. When you hover over the email address field, it becomes highlighted. Click it and choose Follow Up with OmniFocus from the popup menu that appears. The OmniFocus Quick Entry window appears, and it contains an email follow-up task for the contact, including a note with a clickable email link. Creating the Phone Call Followup Script Plug-In The process to create phone call followup plug-in is essentially the same. 1. Quit the Contacts app again. 2. Create another AppleScript Editor document. 3. Insert the following code this time: 4. Save the script as a script named Contacts > Phone Call Follow Up with OmniFocus.scpt into the ~/Library/Address Book Plug-Ins folder in your home directory. Creating an OmniFocus Phone Call Followup Task Launch the Contacts app again. This time, click on a contact's phone number field and choose Follow Up with OmniFocus from the popup menu. Again, OmniFocus' Quick Entry window is displayed. This time, it contains a phone call follow-up task and a note containing the phone number. Voila, you now have quick OmniFocus integration with Contacts, and you can use it anytime you need to schedule a follow-up. Until next time, Happy Scripting!

  • AppleScripting OmniFocus > Send Completed Task Report to Evernote

    by 
    Ben Waldie
    Ben Waldie
    02.18.2013

    I've mentioned before that OmniFocus is my task manager of choice. Each morning, I pull up a list of scheduled tasks for the day, and focus on getting them done. In OmniFocus, I've set up Perspectives (saved window states) for both Due tasks and Completed tasks. What I really want, however, is something that will pull out recently completed tasks and summarize them in Evernote, my note management app of choice. This way, I can maintain a historical log of my progress, and pull out summaries of completed tasks to send to clients. Since this type of integration isn't built into OmniFocus or Evernote, I wrote an AppleScript to do it. Creating the Script NOTE: If you have any trouble following along, you can download my completed script here. 1. Launch AppleScript Editor (in /Applications/Utilities) 2. If your system-wide script menu isn't enabled already, go into AppleScript Editor's preferences window and turn it on. 3. Create a new script document and enter the following code: 4. Bring OmniFocus to the front, and from the system-wide script menu, choose Open Scripts Folder > Open OmniFocus Scripts Folder. This creates the following folder, if it doesn't already exist -- ~/Library/Scripts/Applications/OmniFocus 5. Go back to AppleScript Editor and save the script as OmniFocus > Prepare Task Completion Report into the ~/Library/Scripts/Applications/OmniFocus folder you opened in the last step. Running the Script Bring OmniFocus to the front. Next, select OmniFocus > Prepare Task Completion Report from the script menu. The script starts by asking for the scope of the report. Your options are to summarize tasks from today, yesterday, this week, last week or this month. Choose one, and click OK. Next, the script retrieves a list of tasks within the specified timeframe, formats them as HTML, brings Evernote to the front, and creates a new note. You've now got a summary of recently completed tasks in Evernote. Do you feel productive yet? Until next time, happy scripting!

  • Friday Favorite: Using AppleScript to work with tasks in Things 2

    by 
    Kelly Hodgkins
    Kelly Hodgkins
    02.15.2013

    A few weeks ago I purchased Things 2 when it was on sale in the Mac App Store. I've used the demo before and have always enjoyed the simplicity of the Things interface and the power of its tagging system. One difficulty that I faced with Things is its closed environment, which keeps all your tasks inside the app. That's great if you work only with Things, but not so convenient if you want to share your tasks with other apps or other people. You can drag and drop your tasks individually to other apps like OS X Calendar, but the easiest way to export your tasks is to use AppleScript and transfer them in bulk. One script I regularly use is this export Things to text script from Dexter Ang (thepoch) on github. This script exports the Things database to the desktop as Things Backup.txt. You can tweak the script to export certain parts of the Things database like your Today tasks or Next tasks. This is very handy as you can then edit the text file and upload it to Google Docs or any other app that'll import and format a text document. Another one of my favorite scripts is this Reminder export script from NightLion.net. This script lets you export all the tasks in your Today list and import them into the OS X Reminders app. I've been using this script each morning to pull my tasks down into Reminders, which I then use to set flexible notifications for the tasks. The last script that I've adopted is this Mail To Things script posted by marekz on the Cultured Code forums. This script lets you select a message in your OS X Mail inbox and send it quickly to Things. The task will appear in your Things Inbox with the subject as the name of the task and a link to the email in the notes. These are just a few scripts that I have found during my initial weeks with Things. If you have any favorite scripts, please share them in the comments. If you want to create your own scripts, you should check out Cultured Code's PDF guide to using AppleScript with Things as well as our growing list of AppleScripts for OS X.

  • AppleScripting Dates > Elapsed Time Calculator

    by 
    Ben Waldie
    Ben Waldie
    02.11.2013

    Since Valentine's Day is this week, I thought I would take this opportunity to share an AppleScript I wrote to calculate how long my wife and I have been married. With this baby, I'll never be accused of forgetting how long it's been when our anniversary rolls around. The script determines the elapsed time between now (the current date and time), and a prior date and time (such as our anniversary). It then displays the result in seconds, minutes, hours, days, weeks, months and years. Note: If you're into the whole "traditional anniversary gift" thing (I'm not), you can find a list of gift categories on Wikipedia. Creating the Script Note: If you have any trouble following along, you can download the complete script here. 1. Launch AppleScript Editor in /Applications/Utilities and create a new script document. 2. Insert the following code: Some notes about this script... * I used some of the number calculation handlers in the Essential Subroutines section of macosxautomation.com, although, I made some slight modifications to them for the script. If you're interested in learning more about AppleScript, there are some other useful handlers there, as well, and I encourage you to check them out. * The final display dialog sets as its icon the FavoriteItemsIcon icon file, which is embedded in the CoreTypes bundle in /System/Library/CoreServices. It is, coincidentally enough, a heart. Using the Script To use, just run the script within AppleScript Editor, or save it as an application to be launched and run whenever you wish. First, the script asks you to enter a date and, optionally, a time. Next, the script does its calculations and displays the result. Just take a screenshot of the dialog and send it along to your significant other. Until next time, Happy Scripting and Happy Valentine's Day Week!

  • AppleScripting Notification Center > Scheduling Do Not Disturb

    by 
    Ben Waldie
    Ben Waldie
    02.04.2013

    Mountain Lion's Notification Center is great for keeping you in the loop, but it can be a huge distraction when you need to get stuff done. Sometimes, a little peace and quiet is all you need to stay productive. As you may know, iOS 6 includes a handy Do Not Disturb feature, which can be turned on to disable notifications. It can even be set to automatically enable/disable itself at scheduled intervals. Mountain Lion also lets you disable Notification Center. Just open Notification Center and drag down to access a Show Alerts and Banners toggle switch. Note that this is a temporary setting, and disabled notifications automatically re-enable at midnight. Unlike iOS 6, though, Mountain Lion doesn't give you an option for enabling/disabling notifications on a schedule. At least, it doesn't provide a built-in option for this. With a little customized help from AppleScript, Automator, and the Calendar app, it is possible. In this post, you'll create two Calendar Alarm Automator workflows, which can be configured to run at scheduled times to enable or disable Notification Center alerts and banners. Note: If you have any trouble following along, you can download the completed AppleScripts and Automator workflows here. Building a Workflow to Enable Do Not Disturb (i.e. Disable Notification Center Alerts and Banners) 1. Launch Automator (in your /Applications folder) and create a new Calendar Alarm workflow. 2. Search the action library for the Run AppleScript action and drag it to the workflow area. 3. Replace the pre-filled AppleScript code in the Run AppleScript action with the following: The script writes to Notification Center's property list file and enables Do Not Disturb mode. It then quits and relaunches Notification Center in order for the change to go into effect. 4. You're finished building the workflow, so go ahead and save it as Enable Do Not Disturb. 5. When you save the workflow, Automator puts it where it needs to go (the ~/Library/Workflows/Applications/Calendar folder). The Calendar app launches and a new event is created in an Automator calendar, which Automator creates if it doesn't already exist. The event should be configured with an Open File alarm that's set to run the workflow. Schedule the event for the desired time, such as every weekday morning at 6 AM. Now, every time the event occurs, the alarm should launch the workflow and Notification Center should be disabled. As I mentioned earlier, Notification Center automatically re-enables each day at midnight. So, if you plan to schedule Do Not Disturb overnight, then you'll need to create an additional event that disables it again at 12:01 AM. Building a Workflow to Disable Do Not Disturb (i.e. Re-Enable Notification Center Alerts and Banners) Now that you've got a workflow to disable Notification Center, you probably want one to re-enable it. 1. Create another new Calendar Alarm workflow in Automator. 2. Search the action library for the Run AppleScript action again and drag it to the workflow area. 3. This time, replace the existing placeholder script in the Run AppleScript action with the following code: This code updates Notification Center's property list file to disable Do Not Disturb. Then, it relaunches Notification Center for the change to take effect. 4. The workflow is done, so save it as Disable Do Not Disturb. 5. The Calendar app should launch again and another event should be added to the Automator calendar. This event should be configured with an Open File alarm that's set to open the Disable Do Not Disturb workflow. Set it to run on the desired schedule, such as every weekday morning at 9 AM. If everything has gone according to plan, you should now have Do Not Disturb workflows that disable and re-enable Notification Center alerts and banners at the desired times. Use your alert-free time wisely. Until next time, happy scripting!

  • AppleScripting Evernote > Embedded Image Scaler

    by 
    Ben Waldie
    Ben Waldie
    01.28.2013

    I'm a big fan of Evernote. I use it for archiving ideas, writing articles / blog posts and lots more. I often insert screenshots and other large images into my notes. Screenshots can be pretty big, and I usually don't want giant images filling up my notes. I keep wishing Evernote offered a way to resize embedded images, so I could insert thumbnails. At the moment, it doesn't. So, I decided to write my own app to resize embedded images. Here's how you can do the same... Creating the Script App My script app uses Image Events, a background app in OS X, to do the scaling. So, no third-party software (other than Evernote) is needed for this to work. Note: If you have any trouble following along, don't worry, you can download the complete script app here. 1. Launch AppleScript Editor and create a new script document containing the following script: If you're familiar with AppleScript, then you'll notice this script uses an open handler, making it a droplet. When triggered to process an embedded image in an Evernote note, the image is actually passed as if it was dropped on the script app. 2. Save the script as an application named Evernote > Scale Embedded Images to your Applications folder or another folder of your choice. 3. Go to the saved script app and Control+Click on it to reveal the Finder's contextual menu. Choose Show Package Contents to view the contents of the saved app bundle. 4. Navigate to the Contents folder within the script's bundle and open the Info.plist file in TextEdit, TextWrangler or your other favorite text editor. 5. Change the CFBundleDocumentTypes key's array to the following: This Info.plist change sets the script app to only accept JPEGs, PNGs and TIFFs, and for the script app to appear as an image editor. Image Events can process other types of images too, including BMP, GIF, PSD and PICT. So, if you think you may be embedding those types of images in your notes, go ahead and add extensions for them too. 6. Save and close the edited Info.plist. You're done. The script app is ready for use. Resizing Embedded Images in Evernote Please note that your script app scales embedded images in Evernote notes. When an image is scaled, you can't revert back to the unscaled version. So, be pretty darn sure you want to scale an image before triggering the script. 1. Open an Evernote note containing an embedded image. 2. Control+Click on an embedded image and choose Open With. You should see your script app in the list of supported apps. Choose Evernote > Scale Embedded Images. Evernote launches the script app and passes it the selected embedded image. 3. When prompted, choose the desired size. Options are Low (320px on the longest side), Medium (640px) or High (1280px). Or, you can select Custom to enter another size. The script opens the embedded image, scales it accordingly and saves it. Evernote detects that the image has been changed, and updates the note to reflect the new scaled version. Congratulations, you've just expanded Evernote's feature set. Anytime you want a smaller version of an embedded image, your script app is ready to help. Also, while this script is intended for Evernote, you can use it outside of Evernote too. Just drag and drop JPEGs, PNGs or TIFFs onto the script app to scale them too. Until next time, happy scripting!

  • Mac Productivity > 10 TextExpander Date Snippets

    by 
    Ben Waldie
    Ben Waldie
    01.21.2013

    TextExpander (Smile Software) is a utility I use each and every day on my Mac to save time and increase productivity. One of the things I use it for is formatting and inserting dates and times -- adding the date or time to a file or folder name, into an email, a document and so on. In this post, I've shared some of my most used date and time snippets. I hope you find them as useful as I do. If you're not a TextExpander user, I encourage you to give it a try. You can download a trial version on the Smile Software website. Let me give you a little background on how it works. The concept of TextExpander is simple. You start by creating snippets of text. You then assign abbreviations to those snippets. Whenever you type an abbreviation into any app on your Mac, presto! The corresponding snippet is inserted, replacing the abbreviation you typed. TextExpander also includes some power-user features, such as macros, which let you to insert variable information into your snippets, like dates and times. This is what I'm sharing here -- some of the macros I use for inserting dates. I've provided a brief description of each snippet, as well as the snippet code (the macro), and the abbreviation I use. Feel free to adjust accordingly to meet your own needs. 1. Current Date -- Long: This snippet actually comes with TextExpander as an example. It's used to insert the current date in Month, D, YYYY format, i.e. January 9, 2013. I consider this a long date, and changed the abbreviation, so as not to conflict with my other snippets. Snippet: %B %e, %Y Abbreviation: CDATEL 2. Current Date -- Short: This snippet inserts the current date in YYYY-DD-MM format, i.e. 2013-01-09. This is a good format to use when applying dates to file and folder names, as it allows them to be sorted by year, month and day. Snippet: %Y-%m-%d Abbreviation: CDATES 3. Current Time - Long - This snippet inserts the current time in H:M:SS AM/PM format, i.e. 10:00:00 AM. While this format is good for inserting into emails or documents, it's not so good to use on file or folder names, due to its use of colons. Snippet: %1I:%M:%S %p Abbreviation: CTIMEL 4. Current Time -- Short: This snippet inserts the current time in HH-MM-SS format, i.e. 10-00-00. This is a good format to use when applying times to file and folder names, as it doesn't contain any colons. It also uses 24-hour time, in order to avoid potential file name conflicts. Snippet: %H-%M-%S Abbreviation: CTIMES 5. Month and Year: This snippet inserts the current month and year, in Month YYYY format, i.e. January 2013. I often need to reference the current month in this manner when writing emails. Snippet: %B %Y Abbreviation: MDATE 6. Yesterday: The following snippet subtracts one day from the current date and inserts it in YYYY-MM-DD format, i.e. 2013-01-08. Snippet: %@-1D%Y-%m-%d Abbreviation: YDATE 7. Tomorrow: The following snippet adds one day to the current date, and inserts it in YYYY-MM-DD format, i.e. 2013-01-10. Snippet: %@+1D%Y-%m-%d Abbreviation: TDATE 8. Future Date: The following snippet can be customized to add a specified number of days to the current date, in YYYY-DD-MM format. I have several versions of this snippet for two, three and four days in the future. Snippet: %@+(INSERT NUMBER OF DAYS HERE)D%Y-%m-%dd Abbreviation: FDATE(NUMBER OF DAYS) I.e. For two days in the future: Snippet: %@+2D%Y-%m-%dd Abbreviation: FDATE2 9. Next Sunday: I often need to refer to next Sunday in emails, invoices and so on in YYYY-MM-DD format. This goes beyond what TextExpander's built-in macros can do, so I resort to AppleScript. Just set the content type of your snippet to AppleScript, and paste in the following code: Snippet: Abbreviation: NEXTSUN 10. Current Week Range: I also sometimes need to insert a range of dates representing the current week. Again, this goes beyond the capabilities of TextExpander's build-in macros, so I use AppleScript. Again, set the content type to AppleScript, and paste in the following: Snippet: Abbreviation: CWEEK

  • AppleScripting OmniFocus: send due tasks to iTunes

    by 
    Ben Waldie
    Ben Waldie
    01.14.2013

    OmniFocus is a great tool for keeping us organized. But, let's face it. We're busy people. That's why we need a task management app in the first place. How can you take your productivity to the next level? How about having your daily OmniFocus tasks read to you as you drive to work? With a little help from AppleScript and Automator you can make that happen. Here's how... Setup In order to run this script and workflow, you'll need to make sure you have an OmniFocus perspective named Due, and that it's set up to display any tasks that are considered Due Soon. This is a default perspective, so you probably already have it. You can adjust what's considered Due Soon in the Data section of OmniFocus' Preferences window, under Dates & Times. Building the Workflow Note: If you get stuck or have trouble following along, you can download the complete AppleScript and Automator workflow here. 1. Launch Automator and create a new iCal Alarm workflow. Creating an iCal Alarm workflow in Automator 2. Find and add the Run AppleScript action to the workflow, and enter the following AppleScript into the action's script area. When run, this script opens OmniFocus, displays the Due perspective, retrieves a list of tasks, and generates an audio file on the Desktop. The Run AppleScript action handles the OmniFocus work 3. Add the Import Audio Files action to the workflow, and set it to Delete source files after encoding. This action imports the audio file and cleans up afterward 4. Insert the Add Songs to Playlist action. Set it to add to a New playlist named OmniFocus. This action adds the imported audio file to the OmniFocus playlist. It only creates it if it doesn't already exist. 5. Save the workflow as OmniFocus > Send Due Tasks to iTunes. When you do this, iCal opens and a new event is added to an Automator calendar, which is created if it doesn't already exist. The event is configured with an Open File alarm set to run the workflow. Saving the workflow puts it in the proper location and automatically creates an iCal event 6. Set the workflow to run each day at the desired time. You can set the workflow to run anytime you want Once configured, the workflow should run as scheduled. When it does, it should retrieve list of your OmniFocus due tasks, convert them to audio, and import them into an OmniFocus playlist. Example Due tasks in OmniFocus The imported audio task list can be added to your iPhone for on-the-go access

  • AppleScripting OmniFocus > Swap Task Names and Notes

    by 
    Ben Waldie
    Ben Waldie
    01.07.2013

    I use OmniFocus on a daily basis to keep track of important tasks. On a few occasions, I've entered tasks and assigned notes to them, only to decide later that I'd rather use the note as the task name, and the task name as the note. Rather than manually cycling through my tasks and swapping the notes, I wrote an AppleScript to do it. Now, anytime I want to perform this task, I can simply run the script. Here's how I did it... Creating the Script 1. Launch AppleScript Editor (in /Applications/Utilities). 2. If your system-wide script menu isn't enabled already, go into AppleScript Editor's preferences window and turn it on. The script menu is enabled in AppleScript Editor's preferences window. 3. Create a new script document and enter the following code: Note: You can download the complete script here. 4. Bring OmniFocus to the front, and from the system-wide script menu, choose Open Scripts Folder > Open OmniFocus Scripts Folder. This creates the following folder, if it doesn't already exist - ~/Library/Scripts/Applications/OmniFocus. The script menu automatically creates application script folders if they don't exist 5. Go back to AppleScript Editor and save the script as OmniFocus > Swap Selected Task Names and Notes into the ~/Library/Scripts/Applications/OmniFocus folder you opened in the last step. Scripts added to the OmniFocus scripts folder appear in the script menu only when OmniFocus is in the front Running the Script To run the script, just select one or more tasks in OmniFocus. Then, select OmniFocus > Swap Selected Task Names and Notes from the script menu. The script retrieves the selected tasks, loops through them, and swaps their names and notes. You can run the script a second time, if you decide you'd rather swap them back. Some OmniFocus tasks with notes Trigger the script from the script menu to process selected notes The script warns you that swapping task names and notes will remove any note formatting The script notifies you when processing is complete. It skips any notes that contain attachments, and lets you know if this occurred. The processed OmniFocus tasks, with swapped names and notes Whether you need to swap task names and notes or not, this should give you some insight into the scripting capabilities of OmniFocus. I'll be posting other OmniFocus scripts in the future. So, if you're an OmniFocus user, stay tuned. If you're not an OmniFocus user, then you should be. Go to the Omni Group's website and download the trial today! Happy scripting!

  • Preparing high-res icon files with Automator

    by 
    Ben Waldie
    Ben Waldie
    12.31.2012

    This week's post is for all those Mac app developers out there. If you're not an app developer yet, it's a new year, and I'm sure becoming an app developer is at at the top of your resolution list. In any case, if you plan to develop apps, then you need to prepare icons for those apps. Apple provides very specific requirements for generating high resolution icons, which you can find listed on the Apple Developer Connection website. In the past, Xcode came with a tool named IconComposer, which could be used to generate icon files. This tool, however, didn't generate high res icon files, so Apple now discourages its use. Instead, Apple provides instructions for generating icons using an iconset, a folder of image files that can be converted to an icon file using either Xcode or the iconutil command line tool. There are, of course, other ways of creating icons. In this post, however, we'll focus on an iconset. To manually generate an iconset folder, you start by creating a square image to serve as your icon. Next, you generate versions of the image scaled to 16x16, 32x32, 128x128, 256x256, 512x512. These scaled versions are to be named as follows: icon_16x16.png icon_16x16@2x.png icon_32x32.png icon_32x32@2x.png icon_128x128.png icon_128x128@2x.png icon_256x256.png icon_256x256@2x.png icon_512x512.png icon_512x512@2x.png You place all of these images into a folder named FolderName.iconset. Then, you can process it with iconutil to generate an icns file. Sure, creating scaled images and processing them isn't too difficult, but it's a lot of repetitive work. If you create icons regularly, it can get tedious. You're probably thinking, surely, Automator can be used to streamline the process. It can. Here, we'll create an application workflow you can run anytime you want to convert an image to an icon file. Let's get started... Note: If you're an iOS developer, feel free to adjust the workflow below accordingly. Creating the Workflow Launch Automator and create a new Application workflow. Next, insert and configure the following actions. Note: This workflow is pretty long and repetitive. It's easy to get lost. If you get stuck, don't worry, you can download the complete workflow here, along with a sample icon image. 1. Ask for Finder Items - Set this action to ask for an image file at least 1024x1024 in size. 2. New Folder - Set this action to create a folder named MyIcon.iconset on your Desktop. 3. Set Value of Variable - From the popup menu in this action, choose New Variable and create a variable named iconset folder. 4. Get Folder Contents 5. Change Type of Images - Set this action to convert images to PNG format. 6. Scale Images - Set this action to scale the image to a size of 1024 pixels. 7. Rename Finder Items - Set this action to name a single item's basename only to icon_512x512@2x. This represents a 1024 image (i.e. a Retina display ready size) when the icon is created. Note that this action's title changes in the workflow to reflect the type of naming, in this case Name Single Item. 8. Duplicate Finder Items 9. Scale Images - Set this action to scale the image to a size of 512 pixels. 10. Rename Finder Items - Set this action to name a single item's basename only to icon_512x512. 11. Duplicate Finder Items 12. Rename Finder Items - Set this action to name a single item's basename only to icon_256x256@2x. 13. Duplicate Finder Items 14. Scale Images - Set this action to scale the image to a size of 256 pixels. 15. Rename Finder Items - Set this action to name a single item's basename only to icon_256x256. 16. Duplicate Finder Items 17. Rename Finder Items - Set this action to name a single item's basename only to icon_128x128@2x. 18. Duplicate Finder Items 19. Scale Images - Set this action to scale the image to a size of 128 pixels. 20. Rename Finder Items - Set this action to name a single item's basename only to icon_128x128. 21. Duplicate Finder Items 22. Scale Images - Set this action to scale the image to a size of 64 pixels. 23. Rename Finder Items - Set this action to name a single item's basename only to icon_32x32@2x. 24. Duplicate Finder Items 25. Scale Images - Set this action to scale the image to a size of 32 pixels. 26. Rename Finder Items - Set this action to name a single item's basename only to icon_32x32. 27. Duplicate Finder Items 28. Rename Finder Items - Set this action to name a single item's basename only to icon_16x16@2x. 29. Duplicate Finder Items 30. Scale Images - Set this action to scale the image to a size of 16 pixels. 31. Rename Finder Items - Set this action to name a single item's basename only to icon_16x16. 32. Get Value of Variable - Set this action to get the iconset folder variable you created way back at the beginning of the workflow. You also need to set this action to ignore its input, so it doesn't continue processing the 16x16px image from the previous action. Select Action > Ignore Image. 33. Run Shell Script - Set this action to pass input as arguments. Then, enter the following command: iconutil -c icns "$@" Preparing the Run the Workflow Before you begin running the workflow, you need an image you can convert to an icon. Note that iconutil requires this image to be square. So, make sure it is. If you really want to be sure it's square, you can insert a Crop Images action between steps 5 and 6, and configure it to crop to 1024x1024, scaling to the shortest side before copping. However, if your image contains transparency, this action will remove it. So, it's best to prepare your starting image as a square. Running the Workflow When you run the workflow, you're first asked to choose an image. Select the desired image and click Choose. The workflow runs, an iconset folder is created on your Desktop and passed to iconutil, which generates an icns file. You're ready to plug your icns file into your app. Now, any time you need to generate an icon, just create a square image and trigger your workflow. Happy New Year and Happy App Developing!

  • AppleScript Desktop Icon Race

    by 
    Ben Waldie
    Ben Waldie
    12.24.2012

    Scripty Claus' gift to you this Holiday Season is a fun little AppleScript that lines up your Desktop icons and races them across the screen until one of them reaches the finish line. Here's how to set it up... Note: You can download the complete script here. 1. Launch AppleScript Editor in /Applications/Utilities. 2. Enter the code shown. 3. Run the script to start the fun. When the script runs, it calculates how many icons are allowed in the race and lines the lucky contestants up along the left side of your screen. Any remaining icons are deemed spectators, and are lined up along the right side of your screen. The race begins and the contestants randomly race to the virtual finish line on the right side of the screen. The first one to reach the finish line is the winner. At the end of the race, your icons are moved back to their original locations. Pre-race Desktop Starting the race A winner is announced! Happy Holidays and Happy Scripting!

  • Where Automator Actions and Workflows Live

    by 
    Ben Waldie
    Ben Waldie
    12.17.2012

    Automator's great for streamlining some of the repetitive things you do each day on your Mac. With Automator, you can create your own custom plugins for the Services menu, Folder Action workflows that run when files are placed into a folder, add-ons for the print window's PDF menu, and more. In most cases, when you save a workflow, Automator puts it where it needs to go automatically. But, where do your workflows actually live? If you want to remove or edit one, you'll need to know. In this post, we'll take a look at the various places workflows are found on your Mac. Actions Before exploring the different resting places for workflows, let's discuss actions. Actions are the building blocks of your workflows. To use them, they need to be installed somewhere Automator can find them. There are four places actions can reside on your Mac: Apps - Often, an app that supports Automator contains embedded actions. When Automator launches, it scans the apps on your Mac, loads their actions (if they have any), and displays them in the action library. Aperture is an app that contains embedded Automator actions /System/Library/Automator - This is where Apple puts all of the standard actions that come with OS X, such as actions for Calendar, Mail, and Safari. /Library/Automator - Here, you may find some non-embedded third-party actions. The Microsoft Office actions, for example, are installed here. Actions in this folder are available to all user accounts on your Mac. ~/Library/Automator - If you double-click action files you've downloaded or choose File > Import Actions... in Automator, the actions are installed here automatically. These actions are available to you, but not to other users on your Mac. Actions are installed into one of the three /Library/Automator folders Note: To access the Library folder in your home directory, press Option and choose Go > Library from the Finder's menu bar. Workflows Automator's template chooser panel gives you lots of choices when creating workflows Automator allows you to construct workflows in a variety of formats, each of which has its own benefits and use cases. When you build a workflow, you choose the most appropriate format for your needs. Then, when you save the workflow, Automator either asks you to choose an output folder, or it saves it automatically into a specific location based on the workflow's format. Applications Automator workflow applications are just like other apps. You double-click them and they run. When you save a workflow as an application, Automator allows you to choose its location. You can put it anywhere, such as your Applications folder, Documents folder, etc. Once saved, you can even drag it to your Dock for quick access. Workflows A workflow file is a saved Automator document. Double-click it to open it in Automator for editing. Like applications, workflow files can be saved anywhere you wish. Calendar Alarms A Calendar alarm workflow is a specifically configured application, that is intended to be run from a Calendar event's alarm at a scheduled date and time. These types of workflows are saved into the ~/Library/Workflows/Applications/Calendar folder in your home directory. A Calendar Alarm workflow is configured to run from an Open File alarm Automator installs Calendar alarm workflows into your ~/Library/Workflows/Applications/Calendar folder Services Service workflows appear in the Services menu and contextual menus throughout OS X. They're typically used to perform some automated function on selected text, files, images, and more. These types of workflows are saved into the ~/Library/Services folder in your home directory. You can move a saved Service into the /Library/Services folder to make it accessible to all users on your Mac. Service workflows appear in the Services menu and contextual menus throughout OS X Service workflows are saved into the ~/Library/Services folder Service workflows can also be enabled/disabled or be assigned to hot keys in System Preferences, under Keyboard > Keyboard Shortcuts > Services. System Preferences provides a place to manage your service workflows Print Plugins Print plugins appear in the PDF menu of the print dialog throughout OS X. They're used to process printed PDFs. For example, you might create a print plugin that renames a printed PDF and uploads it to your FTP server. These workflows are installed into the ~/Library/PDF Services folder in your home directory. Like Services, you can move print plugins into the /Library/PDF Services folder in order for all users of your Mac to access it. Print plugin workflows show up in the print window's PDF menu throughout OS X Print plugin workflows are saved in the ~/Library/PDF Services folder Folder Action Workflows Folder actions are workflows that are attached to folders and configured to run when new files are placed into the folder. Folder actions are saved into the ~/Library/Workflows/Folder Actions/ folder in your home directory. Folder actions can be configured using the Folder Action Setup app, which you can access by Control+Clicking on a folder and choosing Services > Folder Action Setup. You can access Folder Actions Setup via the Finder's contextual menu Folder Action Setup allows you to enable, disable, and edit Folder Action scripts and workflows Image Capture Plugins Image Capture plugins are workflows that appear in the Image Capture app. They can be configured to run to process images as you're downloading them from a camera. For example, you might make an Image Capture plugin that adds copyright metadata to your images, backs them up to an offsite server, and then imports them into iPhoto automatically as they are downloaded. Image Capture plugins are saved into the ~/Library/Workflows/Image Capture folder in your home directory. Image Capture plugins can be set to process your downloaded camera images Script Menu Workflows Finally, although Automator doesn't presently include an option for saving workflows in the OS X script menu, you can place them there yourself. Just save your workflow as a Workflow file or application and move it into the ~/Library/Scripts or /Library/Scripts folder. The script menu offers a nice location for organizing and gaining quick access to scripts and workflows. You can turn on the script menu in the preferences window of AppleScript Editor in /Applications/Utilities. The script menu in OS X also allows you to run Automator workflows You enable the system-wide script menu in AppleScript Editor's preferences window So, now you should have a pretty good handle on where your various Automator workflows reside. If you're still getting started with Automator, this information will no doubt come in handy soon, as you follow along with some of my future posts.

  • Send Keynote presenter notes to Evernote with AppleScript

    by 
    Ben Waldie
    Ben Waldie
    12.10.2012

    We've all been there before. You've prepared a Keynote presentation on the Internet phenomenon of cat videos for your local Mac user group. You've finished editing your slides. You've added presenter notes. Next, you want to extract the notes from your slides and bring them into Evernote so you can look them over and maybe use them as the basis for your forthcoming newsletter article. You open your presentation in Keynote and select File > Export. Then, it happens. You remember that Keynote doesn't have a feature for exporting presenter notes. Sure, you could copy them one by one into Evernote, but that will take a while. Fortunately, you know this can be done quickly and easily with AppleScript. Here's how you'll do it... Creating the Script First, you need to write a script. NOTE: If you have any trouble following along, you can download the complete script here. 1. Launch AppleScript Editor (in /Applications/Utilities). 2. Create a new script document, and enter the following code: 3. Save the AppleScript Editor document in Script format to your Desktop as Send Keynote Presenter Notes to Evernote.scpt. AppleScript Editor documents can be saved as Scripts or Applications. Save your document as a Script. Enabling the Script Menu Next, you need a quick and easy way to trigger the script. You can use the handy system-wide script menu. If it's not enabled on your Mac already, here's how you can turn it on. 1. Choose AppleScript Editor > Preferences... 2. Ensure that the Show Script menu in the menu bar checkbox is selected. Once enabled, you should see a script icon appear in your menu bar. The script menu is turned on in AppleScript Editor's preferences window. Installing the Script Next, you're ready to add your newly created script into the script menu. This way, you can quickly trigger it whenever you're in Keynote with an opened presentation. 1. Go into Keynote. 2. From the script icon in your menu bar, select Open Scripts Folder > Open Keynote Scripts Folder. The script menu provides quick and easy navigation to your scripts folder. 3. Copy the Send Keynote Presenter Notes to Evernote.scpt file from your Desktop into the ~/Library/Scripts/Applications/Keynote folder that opens. The Keynote Scripts folder is created automatically if it doesn't already exist. Running the Script Now that your script is installed, it's ready to run whenever you need it. 1. Open a Keynote presentation containing presenter notes. The presenter notes area is located beneath your slides. If this area isn't visible, choose View > Show Presenter Notes. 2. From the script menu, choose Send Keynote Presenter Notes to Evernote. Application scripts are contextual and automatically appear in the script menu when the target app is frontmost. 3. When prompted, specify whether you would like to extract slide content, in addition to the presenter notes. The AppleScript can extract presenter notes and/or slide content. The choice is yours. The script extracts the slide titles, presenter notes, and, if necessary, the slide content from your opened Keynote presentation. Next, the script reformats the extracted content as HTML, brings Evernote to the front, and creates a new note. An Evernote note containing extracted Keynote notes. Your notes are now ready for review in Evernote on your Mac. Assuming you've got Evernote's iOS app too, your notes are also synced to your iPhone and/or iPad. As you ride the train to work and excitedly begin working on your newsletter article, feel free to share your knowledge of cat videos with the person next to you. Happy scripting!

  • Cascade Finder windows with AppleScript

    by 
    Ben Waldie
    Ben Waldie
    11.27.2012

    You're busy. You've got tons of things going on at any given time. Your Mac's screen is constantly cluttered with a bazillion Finder windows, and you keep shuffling them around to find the one you need. Sure, Mission Control in Mountain Lion lets you view all of your Finder windows at once in a pretty tiled view. But, it doesn't sort them, and with a ton of little windows, finding the one you want is no piece of cake. How nice would it be if the Finder had a "Cascade Windows" feature? With a little help from AppleScript, your wait is over. In this post, you'll write a simple AppleScript that sorts your opened Finder windows and cascades them, making it quick and easy to find the one you want and clearing your cluttered screen in the process. Let's get started. Does your screen look like this, with windows everywhere? AppleScript can help. Expose shows your Finder windows, but it's still not always easy to find the one you need If you get stuck with any of the scripting in this post, you can download the complete scripts here. Prep Work First, you'll need some opened Finder windows. If you're interested in the topic of this post, then odds are good that you already have plenty of opened windows. If not, you can open some, or you can run the following AppleScript to create some for testing. Just open up AppleScript Editor in your /Applications/Utilities folder, paste in the following script and run it. The script creates a folder named Cascade Windows Test on your Desktop, adds 10 subfolders to it, opens them, and randomly positions them on your screen. The Cascade Windows Test script creates a bunch of folders and opens them, ready for cascading. Writing the Script Create a new AppleScript Editor document and paste in the following script. Comments have been provided to explain each portion. Running the Script When you're ready, go ahead and run the script. Or, for quick access, save the script as an application and drag it to your Dock. When run, the script asks you to specify how many pixels you'd like between the menu bar and the first window. A default value of 10 pixels is suggested. Tell the script how far down you'd like the first window positioned Next, the script asks you how many pixels you'd like between the left side of the screen and the first window. Again, a default of 10 pixels is suggested. Tell the script how far over you'd like the first window positioned The script asks you how many pixels high you'd like each window, suggesting 300. Give the script a desired window height The script asks how many pixels wide to make each window, suggesting 350. Give the script a desired window width Choose how far apart you'd like the windows from one another. The default is 25 pixels, and should allow enough space to see each window's title bar. Specify an offset between the cascaded windows Finally, the script asks if you want to cascade the windows to the right. Doing so creates a staggered effect. Choose whether you want your cascaded windows staggered to the right The script finds any opened Finder windows, sorts them alphabetically by folder name, and cascades them. Cascaded Finder windows, staggered to the right Cascaded Finder windows without staggering With your windows cascaded by name, just scan through the title bars to find the one you need and click it to bring it to the front. Your days of searching through a cluttered screen of windows has come to an end.

  • Create Evernote 5 template notebooks with AppleScript

    by 
    Ben Waldie
    Ben Waldie
    11.20.2012

    Evernote 5 is a wonderful app for gathering information and keeping it organized and synchronized between your devices. In Evernote, you create notebooks and fill them with notes. These notes can be anything - thoughts, web clippings, files, photos, audio, etc. Whenever you need to recall information you've added to Evernote, just type in a few keywords to instantly locate it. This post shows how to use AppleScript to create template notebooks that contain default template notes. You can use these templates for creating new projects, jobs, or anything else you might need. Let's get started. To Configure 1. First, go to the Documents folder in your home directory and create a folder named Evernote Templates. 2. Go into Evernote and begin creating some notes to serve as templates for your notebook. Suppose you're creating a template for a design project. You might create template notes for materials, meeting notes, phone notes, a status report, etc. Go ahead and enter placeholder text and assign default tags for these notes, as well. Creating template notes in Evernote 3. Once you've created your template notes, select them all. You're going to export them so they can be imported later when you want to create a notebook. Selecting your template notes in Evernote 4. Choose File > Export Notes to bring up the export window. When prompted, enter a name for your template notebook, such as Design Project, and save it into the Evernote Templates folder in your Documents folder. Make sure you're saving in Evernote XML Format (.enex), and that you've chosen to Include tags for each note. Exporting your template notes as an Evernote XML file 5. Repeat the process for any other template notebooks you might want. A folder of exported Evernote XML files that serve as templates 6. Launch AppleScript Editor, located in /Applications/Utilities, and create a new document. 7. Enter the following script into the document: (If you have any trouble, you can download the complete script here.) 8. Save the script as an application and drag it to your Dock, so you can quickly trigger it at any time. Saving the AppleScript as an application To Use Launch the AppleScript application you saved (if you prefer to test right from AppleScript Editor instead, click Run in the toolbar). First, the script looks in your Evernote Templates folder and retrieves a list of exported .enex files. It then asks you to choose one. Choosing a notebook template Next, the script asks you to enter a name for the new notebook. Type the desired name, and click OK. Entering a notebook name The script creates a new Evernote notebook named accordingly, and imports the chosen .enex file. The script then searches the opened Evernote window for the newly imported notes. A new notebook created from a template Notes imported into the newly created notebook Congratulations, you've written your very own notebook template utility for Evernote! Now, with only a few clicks, you can quickly create notebooks containing pre-existing default notes.

  • Build a photo calendar with Automator

    by 
    Ben Waldie
    Ben Waldie
    11.13.2012

    You've seen it in your Launchpad. You've seen it in your Applications folder. It's Automator. It sounds cool. It looks cool. It's got a cool robot icon. But, what can it really do, and why should you care about it? Well, Automator can do lots of things to improve and streamline your OS X experience. With Automator, you use building blocks called actions like ingredients in a recipe. When your actions are strung together, the result is an Automator workflow that can perform a series of tasks. Apple provides lots of built-in actions for automating things with Calendar, Mail, Safari, and more. You get even more actions as you install Automator-ready apps, like Aperture, BBEdit, Microsoft Office, and Transmit. What you can do with Automator depends on the actions installed on your Mac. So, you may run into limitations if you don't have actions for certain tasks, or if an app doesn't support Automator. For simple things like working with folders, images, and PDFs, however, it's a great tool that can save you time and let you do some fun stuff. In this post, I'll show you how to use Automator to create a print plugin that shows up in the PDF menu when you print a document. This specific plugin lets you print a photo calendar right out of the Calendar app.

  • Send a Tweet via Notification Center using this handy AppleScript

    by 
    Steve Sande
    Steve Sande
    08.21.2012

    Wouldn't it be great if you could send a tweet via Notification Center's "Click to Tweet" feature without needing to take your hands off of the keyboard? Apparently Stack Exchange user Ewwis thought so, too, and he wrote up a nice little AppleScript to do so. Macworld's Kirk McElhearn, who is a fan of AppleScripting and shortcuts, highlighted this script this morning. Just copy, paste and save the script below, launch it with a keyboard shortcut with LaunchBar or another similar utility, and you'll be tweeting in an instant.

  • Dear Aunt TUAW: Help me customize notifications

    by 
    Erica Sadun
    Erica Sadun
    08.14.2012

    Dear Aunt TUAW, I have several Mail accounts. One for work, one personal, and one that gets a lot of junk. I like all of them to come into my Mail app, but I don't need a notification in Mountain Lion every time a piece of junk mail comes through. Is there a way to only enable notifications for certain accounts? Your loving nephew, Billy Dear Billy, Sadly, there isn't a way Auntie knows of to do this with OS X Mountain Lion tools, but why not consider using Growl instead? Growl is the spiritual grandfather to Notification Center. Auntie pinged Uncle Chris from the Growl Project to see what he recommended for you. He pointed Auntie this page, which offers a handy walk through plus an AppleScript that you can customize to your needs. Auntie asked him about Notification Center integration. He replied that the upcoming Growl 2 will be able to forward custom updates to Notification Center instead of using Growl's display. Thanks, Uncle Chris! Auntie brainstormed up with a new motto for the Growl project in appreciation: "Growl: Drinking Notification Center's milkshake since OS X 10.8." Hugs! Auntie T.

  • Trigger private browsing in Safari for specific sites

    by 
    Megan Lavey-Heaton
    Megan Lavey-Heaton
    07.30.2012

    Tony over at Macolyte has posted a good tip on how to enable private browsing in Safari on a particular site. Why would you want this? It's good for when you're viewing financial sites and other sensitive personal data where you don't want to leave a tracking history, for instance. Tony created an AppleScript that will open a new tab for a particular website and set it to Private Browsing mode. That same script can close the tab as well. Be warned though, it sets all open tabs to Private Browsing mode when this happens. (We posted a link to a similar script years ago, but that one also set up a temporary disk image to redirect Safari downloads, in case you inadvertently downloaded something sensitive.) Click through to get Tony's AppleScript. If you've just upgraded to OS X Mountain Lion, check out our look at the new Safari to get some other tips and also find out how to get your RSS button back.