AppleScript

Latest

  • Kill no-close-em Safari pages with AppleScript

    by 
    Erica Sadun
    Erica Sadun
    09.03.2014

    I hate those pop-ups that hijack Safari even when I've enabled Settings > Security > Block Pop-up windows. Sure, I've edited my hosts file with Someonewhocare's updates to avoid them in the first place but even so, bad pages still happen. With a simple web search, you'll find a variety of conventional solutions for these situations. I prefer to close them automatically without interacting with pop-ups directly or force-quitting Safari. Here's where a simple AppleScript application can help. I use AppleScript to tell Safari to "close window 1", i.e. the frontmost window. This dismisses the problematic window on my behalf. I have this script saved to an application (File > Export > File Format > Application) and have docked it for easy access. When bad windows open, my solution is just a click away. Got another fix or an improvement to this one? Drop a note in the comments and share.

  • Daily Update for January 29, 2014

    by 
    Steve Sande
    Steve Sande
    01.29.2014

    It's the TUAW Daily Update, your source for Apple news in a convenient audio format. You'll get some the top Apple stories of the day in three to five minutes for a quick review of what's happening in the Apple world. You can listen to today's Apple stories by clicking the player at the top of the page. The Daily Update has been moved to a new podcast host in the past few days. Current listeners should delete the old podcast subscription and subscribe to the new feed in the iTunes Store here.

  • AppleScript returns to Numbers, and other news for Jan. 29, 2014

    by 
    Michael Grothaus
    Michael Grothaus
    01.29.2014

    AppleScript fans will be happy to learn that Apple has added support for it back into iWork's Numbers app for OS X. The return of AppleScript was first noted by MacWorld: The latest update of Numbers reintroduces AppleScript support in a big way. While Apple could have taken an iterative approach, reintroducing a few commands here and there, it chose instead to go whole-hog: The entire suite of scripting terminology originally supported by Numbers in the 2009 edition of iWork has returned. This means that, if you have Numbers scripts you used with that 2009 version, most of them should (in theory) now work with Numbers 3.1; those scripts may require tweaks, though, because some features of Numbers itself have changed. Apple has also added a few new scripting features to Numbers 3.1, such as the ability to identify the active sheet. Numbers' new AppleScript support has been organized into a suite of scripting terminology labeled Numbers '09 Compatibility Suite, signaling that even more scripting enhancements may be on the way for Numbers-specific features. Apple angered many iWork power users when it removed AppleScript support in October, among other features. Since then the company been slowly replacing what was lost. Hopefully Apple will restore features pulled from Pages and Keynote soon. In other news: The British spy agency GCHQ has reportedly developed tools that allow them to turn any iPhone's microphones on remotely, allowing them to hear what is going on in the iPhone's location. They can also remotely turn any iPhone into a high-precision GPS tracker. AT&T added 1.2 million new postpaid smartphone users last quarter, 566,000 of those being under contract. That's 300,000 fewer than the same quarter a year ago. The US Justice Department is reportedly skeptical about a Sprint acquisition of T-Mobile. Antitrust authorities feel that the merger of the two, which would leave just three national carriers, could hurt competition and be bad for consumers.

  • Friday Favorite: Use AppleScript to delete files from a folder

    by 
    Kelly Hodgkins
    Kelly Hodgkins
    01.03.2014

    As part of my daily writing, I take a lot of screenshots and process a ton of images on my Mac. As a result, I have two ever-growing folders that are stuffed full of images that are not useful after I publish a post. Now that I have a MacBook Air and only 128 GB of storage space, I am much more concerned about keeping my files in check. To help delete these files in bulk, I've been using this handy AppleScript: try tell application "Finder" delete (every item of folder (path to desktop folder) whose name begins with "Screen Shot") delete (every item of folder (path to downloads folder) whose name ends with ".jpg") end tell on error display dialog ("Error. Couldn't Move the File") buttons {"OK"} end try You can modify it yourself to point to a different folder or to target different files. If you remove the qualifier "whose name begins with" and leave the line as "delete (every item of folder (path to desktop folder))", then you can delete all the contents of a folder in one fell swoop. I don't need to run the script every day, so I've exported it as an application and run it once a week. It's not a fancy script, but it is a timesaver, which makes it invaluable for me. Hopefully, it will be of use to you, too.

  • Friday Favorite: How Keyboard Maestro saved my Mavericks macros

    by 
    Erica Sadun
    Erica Sadun
    11.22.2013

    Bless Keyboard Maestro. It's not as if we haven't already given it coverage here at TUAW, but I fought to make it today's Friday Favorite because it pulled my grits out of the fire after I upgraded to Mavericks. Me? I've been a Quickeys user since the freaking 1980's. One gets used to an app. Used to it enough that the thought of having to transition away from my decades-old keyboard macros to a new app was giving me hives. So I resisted, resisted, and then I resisted some more. After Lion debuted, I made excuse after excuse -- dropped a few of my daily macros, adjusted some others, and kept pushing forward with my old system just so I wouldn't have to start again from scratch. Startly, the guys who now own the app, hemmed and hawed, made some noises about eventual upgrades, but I was basically running abandonware. Finally when Mavericks debuted, my decades old macro set gave up the ghost. Even doing some emergency tweaks like switching off App Nap couldn't save my workflow. TJ Luoma, who had had just about enough of my "but my system works...or at least it worked" nonsense finally hit me over the head with a very large clue mackerel1. (The size of the clue-fish indicates how much this matters.) "Just. Use. Keyboard. Maestro." (I paraphrase.) So I did. Several weeks later, I am a rabid Keyboard Maestro fan. From its easy to use editor (with folders!) to its nuanced rule system (I can disable my keyboard Emacs equivalents for Terminal, Xcode, and Text Edit because they're already built into those apps natively), Keyboard Maestro is doing everything that Quickeys ever did for me but is doing it more smoothly, faster (seriously, no playback lag), and reliably. I love this app. It handles app launching, menu selections, complex sequences, and offers a solid Recording option that lets me demonstrate tasks rather than programming them. I can easily enable and disable shortcuts, which allows me to switch instantly from standard development mode to testing out Xcode betas. That's a huge time-consuming task for me usually. (Hint: You can bet I immediately remapped the new documentation keys for Xcode 5.1.) It's not just useful for development. I'm using Keyboard Maestro to apply AppleScript to QuickTime Player, adding timed skip actions for moving forward and back through videos. I've got it set up to enter my family's library card in Safari for when we need to reserve books. It's working in mail, helping to sort mail as I work through my inbox. In other words, it's not only doing all the tasks I normally relied on for my macros, it's opening new opportunities for me as I continue to explore its amazingly wide range of hooks. Keyboard Maestro costs US$36. It's free to download and you have 30 days to try it out before buying. I think I made it to day 3 before whipping out my Visa card. 1 The mackerel was, of course, a holy mackerel.

  • AppleScript and Automator gain new features in OS X Mavericks

    by 
    Steve Sande
    Steve Sande
    10.23.2013

    Mac power users love to play with scripting and automation. If there's something that's repetitive that needs to be done, it's a lot easier just to either use Automator to automate the process or write an AppleScript to dive in a little deeper. With OS X Mavericks, it appears that Apple has added some features that will help "self-developers" who want to add their own capabilities to their Macs and commercial apps. On the other hand, there are fewer scriptable items available in many of the new Apple apps... iCloud Sync To begin with, there's a surprise for anyone who launches either Automator or AppleScript Editor. The first thing you'll find is that both apps were updated with iCloud compatibility. AppleScripts that you've created or Automator workflows can now be moved into the cloud and synced to all of your Macs that are running OS X Mavericks. Sure, that's a little thing, but it's useful if you're creating and updating scripts or workflows that need to be deployed to a handful of Macs automatically. Notifications Want to annoy yourself? AppleScript and Automator now includes a Display Notification command that you can use to send yourself notifications from your own scripts. That's actually quite useful if you want to write a script or run an Automator action that's going to ping you when it's done through Notification Center. There's got to be a way to use this to annoy coworkers... Libraries Now this is cool. Let's say that you have code that can be used in a number of scripts. Now you can create an AppleScript Library, which is a script that contains a frequently used routine. Store that in ~\Library\Script Libraries\, and now any other script can use that code by simply calling it with a new use clause. Write once, use many times. Blogger Don Southard over at MacStories has a good example of how to use libraries in his writeup of scripting and automation improvements in Mavericks. Code Signing This may not sound like a big thing, but it's huge. Apple developers can now generate signed copies of applets and droplets as part of the export process in both AppleScript and Automator. Signing these applets means that users launching them will not get the usual Gatekeeper security warning, and adds an incentive for developers to include easy automation tools in their solutions. Speakable-Workflows Now here's a wonderful addition for those who are creating accessible solutions. If Speakable Items is activated in the Accessibility system preferences, Automator adds a new option to the save dialog to save applets as Speakable Items. With that one click, those items are saved to the Speakable Items architecture and can be executed by speaking the name of the applet. Now, about those new apps... On the bad side, some of the new apps appear to be missing a lot of commands in their dictionaries. For example, opening the dictionary of Pages '09 displayed the following: Compare that to the new dictionary for the current iteration of Pages: What's missing? Well, a lot. The Pages Application Suite used to let you do things like script the addition of a chart or table to a document; the Graphics Suite made it easy to script changes to things like the alpha threshold of an image; and the Text Suite even allowed scripting of things like inserting a table of content to a Pages document or fine-tuning the look of character styles. Can't do that with the new Pages... Hopefully Apple will add these capabilities back in an update to Pages and the other iWork apps. (Thanks to reader Peter P. for noting this omission from Pages.) This is just what I've been able to find -- or not find -- in a cursory look at Maverick's automation tools. As more capabilities and deletions become apparent, this post will be updated. I'd also recommend taking a look at MacOSXAutomation.com, which is always helpful and useful when you're considering the use of the built-in OS X automation tools.

  • Give Apple's reminders a boost with AppleScript

    by 
    Mike Wehner
    Mike Wehner
    07.08.2013

    Reminders is one of those apps that most Mac users probably don't touch, and the vast majority of those who do are likely not getting the most out of it. But with a little added functionality thanks to some basic AppleScript tweaking, Reminders can transform into a more useful tool, allowing you to save browser tab information to your reminder list with just a tap and even instantly bring up a quick reminder entry field for notes whenever you need it. The process is rather simple and involves creating a pair of very basic scripts via OS X's AppleScript utility. You can then map these scripts to your keyboard using any number of launchers -- such as Alfred or Keyboard Maestro. MacStories has the full rundown on the scripts, which you can simply copy and paste into AppleScript in order to give them a test drive.

  • Make an SSB with Chrome on the Mac

    by 
    Michael Rose
    Michael Rose
    05.28.2013

    A site-specific browser (SSB) is a great way to "package" a web app you use every day into a dockable, clickable app that maintains its own cookies, settings and preferences versus your everyday web browser config. On the Mac, the easiest way to make an SSB is via the handy Fluid app, which supports independent prefs in its paid version. Chrome's preliminary "packaged app" support, which will take the SSB concept to the next level, has been supported via dev builds on Windows and Linux since the beginning of the month; you can get a sneak preview of the App Launcher on the Mac, but actual packaged app support is still TBD. If you love the Gmail-savvy simplicity of Mailplane, but can't quite get around the price tag, you might consider an SSB for Gmail, which gives you some of the same functionality. Unfortunately, Fluid builds its SSB support on top of Safari and Webkit, which means your SSB won't be quite as Gmail/Google Docs-savvy as it would be if you were using Chrome. (Try printing a font-heavy Google Docs file from Safari.) There is a way out of this pickle: build an SSB using Chrome as the underlying engine instead. With a quick script and a few Terminal tweaks, you can make a double-clickable fresh Chrome SSB that keeps its own profile well clear of your normal settings. Don't like shell scripts? The CreateGCApp utility packages up the script and does all the work for you. Having a separate instance/SSB of Chrome is particularly handy if you have trouble with Gmail's multiple-account support in your regular browser, as sometimes can happen if one account uses single sign-on via a third party. Once upon a time, you could make SSBs with Firefox via Prism, but that project has been left to wither on the vine. [via Lifehacker & Bracken King]

  • Preview, sips, and more: OS X image processing tools

    by 
    Erica Sadun
    Erica Sadun
    05.16.2013

    On a recent trip, I found I had failed to add copies of my auto-resizing drop tools to my travel MacBook Air. My droplets allow me to convert images to TUAW-standard sizes, namely 225 pixels for small images and 456 pixels for banner images. (See? Information you never thought you'd need to know.) What a lot of people don't realize is that OS X offers solutions for these kinds of basic image tasks. First and foremost is Preview. This app is simply terrific. Yes, I know, Apple took some really helpful utilities like Link Annotation out of the app on its road to Mountain Lion. (Time? Feature trimming? It's hard to say.) Even so, Preview is the best app on your computer that nobody uses enough. Preview offers a surprising tool suite that combines a little bit of Photoshop and a little bit of Acrobat into one app. In addition to annotating PDFs, you can rotate and crop images using Preview's Tools menu. You have access to lasso selection, color correction, and image fitting, among many other features. At one point Steve Sande and I threw around the idea of writing an entire book on Preview (there's plenty of interesting material in there!) but ended up deciding against it. Unfortunately, demand leads sales and too few people know how powerful Preview can be. To resize an image, choose Tools > Adjust Size or click the resizing icon you see at the top-right of this post's main image. The icon looks like an arrowed line in a square box. An Image Dimensions panel slides into view, as you see here. Select the new width you want to use, making sure the small icon next to the two text fields remains in the locked position. This ensures that the height and width scale proportionately, so the resulting image is sized just right. Preview isn't the only resizing solution on your Mac, however. The "sips" command line tool offers another take on image processing, one that's especially convenient for scripting and batch processing. For example, if you want to resize an image to fit a given width, you can ask it to resample to the pixel count you supply. Here's how you might do that. % sips --resampleWidth 225 input.png --o output.png You can also perform many of the same tasks as preview. For example, you might rotate an image clockwise by 90 degrees: % sips -r 90 input.png -o output.png or convert a file from PNG to JPG format: % sips -s format jpeg input.png -o output.jpg OS X also supports related based on "folder actions". These refer to AppleScripts that you attach to folders, so when you drop items into the folders, they run those scripts. It's easy to take a peek at some of the system-supplied actions. Create a new folder on your desktop. Control-click or Right-click it and choose Services > Folder Action Setup from the contextual pop-up menu. Select a pre-built script like "Duplicate as JPEG" or "Rotate Left" and click Attach. Finish by checking "Enable Folder Actions". Your new folder applies the attached script to any file you drop into it. If you're an intrepid system-modding type, you can expand these script choices by adding items to ~/Library/Scripts/Folder Action Scripts. (The system supplied versions all appear in /Library/Scripts/Folder Action Scripts). Scripts are built around a standalone Image Events application, found in /System/Library/CoreServices. This app provides a "faceless background application" that wraps sips for AppleScript scripting. Apple has documented Image Events as part of its developer library, and its docs point to this external website that details how you integrate scripting with image manipulation requests. I'll leave the rest as an exercise for the reader, but a bit of Googling will turn up already-built image solutions ready for testing. Here at TUAW, we regularly use these for image resizing -- and they're exactly the bits I forgot to pack on my trip. So did I get my work done while gone? You bet I did. And a big part of that reason is how sips and Preview enable you to step up to image challenges without any third party software needed. Got some OS X image processing tips? Share them in the comments.

  • Adding copy-to-clipboard rollovers in Contacts app via AppleScript

    by 
    Ben Waldie
    Ben Waldie
    04.29.2013

    Apple's Contacts app includes a lot of great shortcuts for initiating different forms of communication. Just click an email address, phone number or URL field label to display a list of available options. You can send an email, show a phone number in large type or start a FaceTime call, for example. Curiously, one shortcut that's absent from most of these popups is one for copying the email address, phone number, URL, etc. to the clipboard. Mailing addresses are one exception, as they provide an option to copy a mailing label. But, other fields don't include this option. Sure, you could just select a phone number, email address, URL, etc., and press Command+C to copy it. But, what fun is that? It sure would be nice if there were just more handy copy-to-clipboard shortcuts instead. With the help of AppleScript, you can add your own. Here's how... Writing the Script The following steps demonstrate how to add a Copy to Clipboard shortcut to phone number fields in the Contacts app. If you have any trouble following along, you can download the complete script here, along with ones for email address and URL fields too. 1. Launch AppleScript Editor (in /Applications/Utilities) 2. Create a new script document and enter the following code: Note: If you want to create a version of this script for email address or URL fields, just change the action property handler to return the appropriate field type, i.e., on action property return "email" end action property or... on action property return "url" end action property Installing and Using the Script In order for the script you created to appear in the Contacts app, it needs to be saved in the proper place. 1. Quit Contacts if it's running. 2. Save the script you created as Contacts > Copy Phone to Clipboard.scpt, in script format, into the ~/Library/Address Book Plug-Ins folder in your Home directory. If this folder doesn't already exist, go ahead and create it. Now, just relaunch the Contacts app. When you click on a phone number field label, you should see a new option for copying the phone number to the clipboard. Now, repeat the steps above for email addresses and URLs to enhance the Contacts app even further. This marks my last scheduled post for the TUAW for a bit. Hopefully, you'll see more of me here in the future. In the meantime, feel free to reach out to me on Twitter to say "Hello," ask a scripting question or two, suggest a future topic, etc. Until next time, Happy Scripting!

  • Extract App Resource Icons with AppleScript

    by 
    Ben Waldie
    Ben Waldie
    04.22.2013

    Whether I'm preparing for a demo or writing an article, blog post, book, or technical documentation, I often find myself performing the same set of repetitive steps. I need to navigate into an app's packaged resources folder, find one or more icon files, occasionally convert them to PNG and scale them, and add them to my document, Keynote presentation, etc. Fortunately, this doesn't need to be a manual process each time, thanks to the following AppleScript. Creating the Script 1. Launch AppleScript Editor (in /Applications/Utilities) and create a new script document. 2. Enter the following script into the document. NOTE: If you have any trouble following along, you can download the completed script here. 3. Run the script from AppleScript Editor, save it as an app, or add it to your script menu. Running the Script When you run the script, you're first asked to select an app from which to extract icons. Make your selection and click Choose. The script looks inside the app's /Contents/Resources folder for any files with an extension of .icns. If multiple files are found, it allows you to select the ones you want to extract. The default is all of them. Next, the script gives you the option to extract the .icns files themselves, or PNG versions. Click the button to make your choice. If you click the PNG button, then you're given a choice of sizes to create. You might not need the full sized icons, for example. You might only need 256x256 icons. Depending on the options you chose, the script extracts the .icns files, or it converts the .icns files to PNG and scales them, as needed. You're notified when the icons have been extracted, and they're displayed in the Finder for you. Now you can simply drag them to your document, presentation, file, etc., and you're good to go! Happy Scripting!

  • AppleScripting OmniFocus > Send completed task report to Evernote 2

    by 
    Ben Waldie
    Ben Waldie
    04.15.2013

    In February, I provided instructions for using AppleScript to send completed task reports from OmniFocus to Evernote. The script was quite well-received by readers, and I've had numerous requests for enhancements. This post provides an updated version of the script, which includes a number of additions. The script now supports full project paths and additional task details including the context, estimated time, start date, modification date, completion date and notes. This additional content is optional, and you can adjust the script to not display it if you wish. Creating the Script NOTE: You can download my completed script here. 1. Launch AppleScript Editor (in /Applications/Utilities) 2. Create a new script document and enter the following code: 3. At the top of the script, you can adjust various properties to customize the information that's displayed in the report. Just change any of these property values to false to prevent them from appearing. Running the Script You can run the script right from within AppleScript Editor. Or, you can save it and run it from your system-wide script menu, your Dock or wherever else you'd like. When the script runs, just specify the date range you want to include. The script then creates a report for any tasks completed within that specified range in your Evernote Inbox. Now, you can quickly generate much more detailed reports of your recently completed OmniFocus activity simply by running the script. Happy Scripting!

  • AppleScripting Email > Developing a Quoted Reply Service

    by 
    Ben Waldie
    Ben Waldie
    04.08.2013

    A reader recently wrote to me with a problem. Apparently, Microsoft Outlook no longer contains the ability to create quote level chunks of text when replying to messages in plain text format. Why this functionality was removed, I can't say. But, with a little help from AppleScript and Automator, I was able to help the reader to add this functionality back via a Service. Better yet, the Service can be set up to work in any email client, or even system-wide in any app. Here's how you can do it... Building the Service 1. Launch Automator (in /Applications) and create a new Service workflow. Creating a Service workflow in Automator 2. Configure the workflow (at the top) to process selected text in any application, or your favorite email client, such as Mail or Outlook. Then, select the "Output replaces selected text" checkbox. In this screenshot, the Service is set to appear only in the Outlook app. 3. Find and add the Run AppleScript action to the workflow. It should link up with the header, indicating that it receives text as input. Enter the following script into the action. Note: If you get stuck, you can download the completed script and workflow here. Example of the completed workflow 4. The script above is set to limit lines to a maximum of 42 characters. If you want longer lines, go ahead and adjust this in the script. Just set the theMaxLineLength variable to the desired length. Also, note that this is a guideline. The script tries not to break words in the middle. So, if an extra long word is encountered, you may still have lines longer than the maximum length. 5. Save the workflow as Email > Quote Selected Text. Automator puts it where it needs to go. Saving the Service workflow Using the Service Now, anytime you're in your email app and want to create quoted text in a plain text message, just select the desired text. Right-click it (or Option+Click it) to display the contextual menu. Then, select Services > Email > Quote Selected Text. Again, this is intended for plain text messages. It will probably generate inconsistent results with HTML formatted text. Triggering the workflow from the Services contextual menu in Outlook to process selected text in a message If you don't see the Services menu in the contextual menu, then whatever app you're using may not support contextual Services. In this case, try triggering the workflow from the App > Services menu instead. Triggering the workflow from the Application > Services menu If all goes well, your selected text is passed to the Service workflow, and the processed quoted text is inserted. Happy Scripting! A message containing processed text

  • Prank crashes iMessages

    by 
    Kelly Hodgkins
    Kelly Hodgkins
    04.01.2013

    Late last week, several iOS developers were hit with a denial of service attack that used Apple iMessages as the vector. According to a report in The Next Web, Grant Paul (chpawn), iH8sn0w and a half-dozen other developers were flooded with text messages that crashed the iMessages app on iOS. The person or group behind the attack is not known, but The Next Web believes it originated with a Twitter account that sells UDIDs and provisioning profiles to iOS owners who want to sideload pirated apps. The attacker likely used the OS X Messages app and Applescript to automate the sending of text messages. When the attack was in full swing, the recipient is forced to clear a non-stop stream of notifications and messages. Unforunately, there is no way for a user to stop an influx of messages destined for their inbox. Once your iMessage ID is known publicly, anyone can send you an iMessage. Because there is no option to block messages from a specific iMessage sender, you are forced to either read every incoming message or turn off iMessages completely. This problem is compounded in iOS 6 and OS X Mountain Lion as Apple allows you to associate both your phone number and your email address with your iMessage ID. Phone numbers are usually kept private, but an email address can be easy to find with just a bit of Googling. If a malicious person discovers your iMessages email, there is no way to stop him or her from clogging your inbox with messages. Hopefully, Apple reads these reports and develops a way to detect and shut off this bulk spamming before it hits the recipient's devices. For a user, the best way to avoid this type of attack is to keep your iMessage email and phone number out of the public realm. If possible, use a public email address for your website and a private one for your iMessage ID. If your iMessage email is already out there, you can always disable receiving iMessages to that email address. On iOS, you can go to Settings > Messages > Send & Receive to change the numbers and email addresses that can receive a message. On OS X, open the Messages app and select "Messages" from the menu. Then select Preferences and click on the Accounts tab. Click on your iMessage ID and make sure your email address is not selected under the "You can be reached for messages at:" heading.

  • AppleScripting Microsoft Outlook > Announce New Emails By Voice

    by 
    Ben Waldie
    Ben Waldie
    04.01.2013

    In my last post, I demonstrated how to write an AppleScript that verbally announces when new emails arrive in Mail. Some readers asked whether the same thing could be accomplished with Microsoft Outlook. It certainly can. Here's how... Creating and Installing the Script 1. Launch AppleScript Editor (in /Applications/Utilities) and create a new script document. 2. Enter the following script into the document. NOTE: If you have any trouble following along, you can download the completed script here. NOTE: This script was written and tested with Microsoft Outlook 2011, version 14.3.2, running in OS X 10.8.3, Mountain Lion. You can test the script by running it in AppleScript Editor. Select a message or two in Outlook. Then, return to AppleScript Editor and click Run in the script document's window. 3. Make any adjustments to the properties at the top of the script to customize its behavior. For example, if you don't want the script to raise your volume if it's too low, change the raiseVolumeIfNeeded property value to false. If you don't want the script to read the first few paragraphs of each message to you, set the readFirstParagraphsOfEachMessage property value to false. Modifiable Properties in the Script 4. Save the script in Script format to your Desktop as Outlook > Announce New Emails By Voice.scpt. Saving the script to the Desktop 5. Launch Outlook. From its script menu, choose About This Menu... In the dialog that appears, click Open Folder. This opens the Outlook Script Menu Items folder, which is either in your ~Documents/Microsoft User Data folder or your ~/Library/Application Support/Microsoft/Office folder, depending on the version of Office you have installed. The Microsoft Outlook Script Menu Click the Open Folder button to display the Outlook Script Menu Items folder. 6. Move the Outlook > Announce New Emails By Voice.scpt file from your desktop into the Outlook Script Menu Items folder. The Outlook Script Menu Items folder may contain some default scripts provided by Microsoft. Adding an Email Rule Now that you've installed the script, you can run it from the script menu in Outlook. But, you really want a script like this to run automatically when new emails arrive. So, you need to configure a rule to do this. 1. Select Tools > Rules... to display the Rules window. Outlook's Rules window 2. Click the appropriate type of account, i.e. Exchange, IMAP, POP, and click the + button to create a new rule. 3. Name the rule Announce New Emails By Voice and set it to trigger on All Messages. Set the rule's action to Run AppleScript. Click the Script... button and choose your saved script in the Outlook Script Menu Items folder. Click OK to close the rule. The configured rule, set to run your script Now, whenever a new email arrives for the specified type of account, the rule should trigger your script to announce the new messages. If you want to disable the announcements at any time, just go back to the Rules window and de-select the Enabled checkbox next to the rule. Happy scripting! You can disable the announcement script in the Rules window whenever you want

  • Talking to Siri: Remote-controlling your Mac by voice with Siri Listener

    by 
    Steve Sande
    Steve Sande
    03.27.2013

    In this episode of "Stupid Siri Tricks," I make my iOS devices control a remote Mac. How remote? Well, it should work anywhere on the planet (or off, if you happen to be on the International Space Station) with Wi-Fi or a cellular data connection. If you can take a note with Siri, you can make your Mac do your bidding from wherever you may be. I was inspired to do this after watching a video by Niles Mitchell in which he uses a 512K Mac with the original Mac Speak application to issue a command to Siri, which then set a chain of events into motion resulting in some files being moved from that ancient Mac to Dropbox. It occurred to me that he was using the Notes application and iCloud to accomplish all of this. Essentially, you tell Siri to "Write a note", after which you dictate a note and it is synced to all of your devices through iCloud. The lightbulb went on, so I wrote a quick little application in AppleScript to wait for certain notes to appear and then perform actions on the Mac. One of the more useful things I could think of was the ability to shut down my Mac or at least put it to sleep if I forgot to do so before going on a trip, so I set up my application to look for "Shut down" or "Go to sleep" notes to perform either of those actions. Perhaps I want to do a remote restart? All I have to do is tell Siri "Restart my mac" and it happens. I also built in the ability to see what apps are currently running on my Mac and return them to my iPhone or iPad in another note. The possibilities are endless... To use this little "Siri Listener" app, just copy the code below and paste it into a blank AppleScript Editor page. Save the code in case you want to add your own customizations at some point, and then Export as an Application, making sure that you check the boxes for "Stay open after run handler" and "Run-only". To make sure your Siri Listener is always available for your commands, make sure you set it to run at startup. Make sure that you know how to use Siri to take notes. Just press the home button on your favorite iOS device, wait for the Siri prompt, and then say "Write a note". Siri responds with some sort of question about what you want the note to say, after which you can speak the appropriate command. Note that I wasn't thinking clearly when I wrote my initial script -- I actually have to say "What apps are running question mark" to get the note in the proper format for Siri Listener to act upon. I'm probably going to change it to something more generic like "List my mac apps" to avoid the punctuation. I was really wishing that the Photo Booth app was scriptable, as it would be possible to have the Mac's camera take a picture and then attach it to a Note for you to view. I can also see that the Siri Listener idea could be the perfect tool for playing pranks on unsuspecting co-workers, but of course you wouldn't do that... Have fun! And if you come up with some fun and/or productive uses for the Siri Listener, let me know in the comments. Want more Siri tips? There's a book for that.

  • AppleScripting Mail > Announce New Emails By Voice

    by 
    Ben Waldie
    Ben Waldie
    03.25.2013

    You're in the kitchen cooking dinner, or sitting down watching TV, or exercising. Ding! You have a new email. Quickly, run to your Mac to see who it's from. Meh, spam. Ding! Meh, a message from your boss. Ding! Meh. Sure would be nice if Mail could announce who's emailing you. That way, you could just listen for ones you care about. Well, with the help of AppleScript and Mail rules, you can set this up on your own. Think of it as an audible caller ID, but for email. Setting It Up 1. Launch AppleScript Editor (in /Applications/Utilities) and create a new script document. 2. Enter the following script into the document. NOTE: if you have any trouble following along, you can download the completed script here. NOTE: If you wish to test the script, which is always a good idea, you can do so by running it in AppleScript Editor. Just select a message or two in Mail. Then, return to AppleScript Editor and click Run in the script document's window. 3. Make any adjustments to the properties at the top of the script to customize its behavior. For example, if you don't want the script to raise your volume if it's too low, change the raiseVolumeIfNeeded property value to false. If you don't want the script to read the first few paragraphs of each message to you, set the readFirstParagraphsOfEachMessage property value to false. Modifiable Properties in the Script 4. Save the script in Script format to your Desktop as Mail > Announce New Emails By Voice.scpt. Saving the script to the Desktop 5. Launch Mail, open its Preferences window, and click Rules in the toolbar. Mail's Rule Preferences window 6. Click Add Rule to create a Mail rule. 7. Set the rule's description to Announce New Emails by Voice. 8. Set the rule to trigger if any of the following conditions are met: Account matches [Your Account]. If you have multiple accounts, click + and add each one. 9. Set the rule to perform the following action: Run AppleScript. From the list of scripts, choose Open in Finder. Configuring the Mail rule 10. Copy the Announce New Emails By Voice.scpt script file from your desktop into the newly opened folder (this folder is ~/Library/Application Scripts/com.apple.mail in Mountain Lion). Mail's rule scripts folder in Mountain Lion (in ~/Library/Application Scripts) 11. Go back to Mail and close and save the rule. The configured Mail rule, set to run the script Now, whenever a new message arrives for the accounts you specified, the rule should trigger the script, and the messages should be announced audibly. If you get tired of listening to the announcements or want to mute them, just open up Mail's Preferences > Rules window again and de-select the Active checkbox next to the rule. Happy Scripting! You can disable the Mail rule by de-selecting the Action checkbox

  • Triggering AppleScripts from Calendar Alerts in Mountain Lion

    by 
    Ben Waldie
    Ben Waldie
    03.18.2013

    AppleScripts are great tools for increasing your daily productivity. They're even better when they can be set to run unattended, at night, on weekends or during downtime. In Lion, iCal included a handy option for attaching a script to a calendar event. Just create an event, add a Run Script alarm, point it to the desired script and you're good to go. Things changed in Mountain Lion, though. Presumably for security reasons, the Run Script alarm option was removed from the Calendar app. Despite its removal, however, there are still some ways you can trigger scripts from Calendar events. iCal event alarm choices in OS X 10.7 Lion Calendar event alarm choices in OS X 10.8 Mountain Lion Use Automator to Trigger Your AppleScript Although Apple removed the Run Script alarm option in the Calendar app, Automator's ability to save Calendar Alarm workflows wasn't removed. And, since Automator workflows can trigger AppleScripts, they offer a quick and easy workaround for scheduling scripts. Start by launching Automator and creating a new Calendar Alarm workflow. To schedule an Automator workflow, choose the Calendar Alarm template. To Trigger an AppleScript App If your script is an app, you just need to set the workflow to launch it. Add the Launch Application action to the workflow. From the application popup menu, choose Other... and navigate to your saved AppleScript app. The Launch Application action can be used to launch an AppleScript app. To Trigger AppleScript Code If you'd rather not create an app (an app + your Automator workflow means more files to manage), you can embed compiled AppleScript code right within your workflow. Find the Run AppleScript action and drag it to the workflow. Then, insert the desired script code into the action. The Run AppleScript action can be set to run code embedded in your Automator workflow. To Schedule the Script Once you've got your workflow configured, go ahead and save it. Automator automatically adds it to an Automator calendar (which is created if it doesn't exist yet) in the Calendars app. An Open File alarm is added to the event and set to run the workflow. Now, adjust the start date of the event as needed, put it on a repeating schedule, etc. Open File alarms are used to trigger Automator Calendar Alarm workflows. Use AppleScript to Create a Scheduled Event If you create an event in the Calendars app and add an Open File alarm, you should find that you're unable to select a saved AppleScript app. You can select a compiled AppleScript file, but this is essentially useless because when the event triggers, the Open File alarm simply causes the compiled script to open in AppleScript editor. Not what you need. What you really need is to open a saved script app. AppleScript to the rescue. To work around the limitation, just run the following script. It asks you to select a saved AppleScript app. It then creates an event at the current date and time on an AppleScripts calendar, which it creates if it doesn't exist already. The script then adds an Open File alarm to the newly created event and sets it to open your selected script app. Yep, that's right. Although you can't manually set an event to open a saved AppleScript app, you can script the process. NOTE: You can download the complete script below here. So, there you go. A number of workarounds for triggering scripts from Calendar events in Mountain Lion. So, schedule away! Happy Scripting!

  • More Tips for Troubleshooting Automator Workflows

    by 
    Ben Waldie
    Ben Waldie
    03.11.2013

    In my last post, I shared some useful tips for troubleshooting Automator workflow problems. I didn't cover everything, though. There are lots of other ways you can troubleshoot your workflow. Here are some more tips to help. 1. Use Get Selected Finder Items Wisely Automator workflows are frequently created to process files and folders. When you save a workflow as an application, you can drag files and folders onto it and they're passed right into the workflow for processing. Other types of workflows behave similarly. Save a Folder Action workflow, for example, and every time new items are added to the folder, they're automatically passed to the workflow for processing. At the top of a workflow, Automator tells you if it receives files and folders as input. From time to time, however, you may notice that your workflow has processed your files twice, or that it's encountered some kind of obscure error. Often, this is due to the presence of a Get Selected Finder Items action at the beginning of the workflow. As enticing as its name sounds, the Get Selected Finder Items action isn't always needed to process files and folders. Remember, depending on the type of workflow you built, those items may be passed automatically to your workflow. In these cases, the inclusion of the Get Selected Finder Items action causes the dropped items to be appended to themselves. This can result in the items being processed twice or an error. So, what's the solution? Just try removing the Get Selected Finder Items action from the beginning of your workflow. Many times, that one simple change fixes the problem. Don't insert the Get Selected Finder Items action at the start of a workflow if your workflow already receives Finder items as input. 2. Finding Missing Output Files Imagine this. You run an Automator workflow that takes a PDF and outputs its pages as images. The only problem is that the images never seem to show up. Sound familiar? If you've ever been unable to find files output by a workflow, it may not necessarily mean that your workflow failed. Those files may actually be buried somewhere on your system. This is because some Automator actions generate their output files in hidden temporary folders. The Render PDF Pages as Images action is one example. It extracts the pages of a PDF as image files, gives them unique names, and saves them into a hidden temp folder. Render PDF Pages as Images sneakily outputs files to a hidden folder. Note that it doesn't have an option to select an output folder. To determine whether this has happened, run your workflow in Automator. Then, open the action's Results area. If there are files or folders listed, you should be able to figure out where they're located by viewing them in list view. An action's Results area tells you if an action really produced a result. To output the files or folders to the desired location, just insert a Move Finder Items action into your workflow. This should move the items from their secret location to the Desktop or wherever else you choose. Use the Move Finder Items action to move hidden output files someplace more useful. 3. Improving Recorded Task Playback A great feature of Automator is its ability to record things you do manually, so you can play them back later as part of your workflow. A not so great feature of Automator is its knack for being unable to play back what it records. There are a number of reasons this can happen, and some options for fixing things. You may have made a mistake while recording. Remember, Automator is watching. So, it picks up your mistakes too. If this happens, try selecting the extra steps in the Watch Me Do action Automator adds to the workflow. Then, press the Delete key to remove them. You can remove recorded steps by selecting and deleting them. You may have moved too fast, and Automator couldn't keep up. It may have missed some of what you did. You can try to resolve the problem by recording the steps again. This time, take your sweet time. Automator may be unable to repeat what you did manually. Unfortunately, Automator can't access everything in OS X. It can access a lot, but not everything. If this happened, consider trying a third-party macro utility, such as iKey. It may have greater reach than Automator. 4. Locating Missing Actions If you've ever launched Automator but have been unable to locate an action that you used in the past, it may not mean that action is entirely gone from your Mac. Automator may just be unable to load it for some reason. For example, maybe the app the action works with isn't installed anymore. You can see what Automator is unable to load by checking the Console app (in /Applications/Utilities). Just open it up, launch Automator, and see what shows up in the Console. The Console app tells you what actions Automator can't load. Here, the Entourage actions weren't loaded because I don't have Entourage installed anymore. I now have Outlook installed. 5. Service Workflows Not Triggering? Have you created service workflows, but when you trigger them, they don't seem to run? Give them some time. For whatever reason, they may take some time to get going. After one has run, however, subsequent service workflows should run a bit faster. You may have also noticed that you can assign keyboard shortcuts to Service workflows. If you haven't noticed this, you can do it in System Preferences > Keyboard > Keyboard Shortcuts. Assigning a keyboard shortcut to a Service workflow Once you've assigned a keyboard shortcut, you may have found that the workflow doesn't run when you press the keyboard shortcut. One possible fix is to manually choose the workflow from the application's Services menu. Then, once it's been triggered for the first time, the keyboard shortcut often starts working again. Hopefully, these tips and my prior tips have put you on the path to more stable and reliable workflows. Good luck and Happy Scripting!

  • Watch a vintage Mac 512K talk to an iMac via Siri

    by 
    Kelly Hodgkins
    Kelly Hodgkins
    03.11.2013

    Niles Mitchell has a variety of Apple devices, including an iPhone with Siri, an iMac and a vintage Mac 512K. Using a combination of the old Speak program, AppleScript and iCloud Notes, Mitchell was able to send files from his iMac to his Mac 512K via Siri. It's a clever mix of old and new technology that's worth a watch, even just to hear the antiquated sound of a floppy drive working hard to copy files. You can check out this Siri-mediated conversation in the YouTube video embedded below.