Showing posts with label Menu bar. Show all posts
Showing posts with label Menu bar. Show all posts

Tuesday, June 14, 2011

How to Automatically Pause and Resume Music using AppleScript - Apple

Use AppleScript to Automatically Pause and Resume Music


Source: thenextweb.com

Here’s a tiny tutorial to achieve the same result as Take Five using AppleScript.
If you’re not too sure what AppleScript is, wikipedia explains:
AppleScript is a scripting language created by Apple Inc. and built into Macintosh operating systems, [...] designed to exchange data between and control other applications in order to automate repetitive tasks.
To put simply, it’s a scripting language with a syntax that very closely resembles the English language that lets you control most applications on your Mac. We’ll see that in a minute.
1. First, we need an app to invoke our AppleScript using a global shortcut. I personally recommend FastScripts — a little menubar utility for running AppleScripts, but you can also choose to use QuickSilver or Launchbar. Download and install any of these apps and proceed to the next step.
2. We need to write an AppleScript that will automatically pause iTunes and wait for X minutes before resuming playback again. Launch the AppleScript Editor app from your Utilities folder and create a new script with the following code:
if appIsRunning("iTunes") then
tell application "iTunes"
pause
delay 120
play
end tell
end if
on appIsRunning(appName)
tell application "System Events" to (name of processes) contains appName
end appIsRunning


The code has a delay of 120 seconds or 2 minutes by default, but you can change it to any value you like.
3. Save this script to Macintosh HD/Library/Scripts folder as itunes.scpt. Alternatively, you can click FasctScripts’ menubar icon to “Open Scripts Folder” under FasctScripts menu. Once saved, the script should automatically show up under the FastScript menu.
4. Go to FastScripts’ preferences and navigate to the “Script Shortcuts” tab to assign a global shortcut to this script. I personally use Cmd+Shift+P.
5. Fire up iTunes and start playing your favorite playlist. If and when you want to temporarily pause your music, just hit the global shortcut key you just assigned and the script will do its thing.
Unfortunately, the other popular music apps such as Spotify and Rdio do not support AppleScript natively i.e they do not answer to the pause/play or similar commands. For this reason, it isn’t easy to achieve the same functionality as you can for iTunes. While there is a way to write an AppleScript to do this, it’s not guaranteed to work for you. Here’s the code for Rdio:
if appIsRunning("Rdio") then
tell application "System Events"
tell application "Rdio" to activate
tell process "Rdio" to click menu item "Pause" of menu "Controls" of menu bar 1
   delay 10
tell process "Rdio" to click menu item "Play" of menu "Controls" of menu bar 1
end tell
end if
on appIsRunning(appName)
tell application "System Events" to (name of processes) contains appName
end appIsRunning


Hopefully, these apps will add AppleScript support in the future. Until then, I guess I’ll just have to manually resume playback.
The AppleScript for iTunes presently resumes playback at the set volume instead of fading in the music, so an improvement to the AppleScript would be to add the code to fade in the music after playback resumes. AppleScript can achieve some really complex tasks with a few lines of code, so I’ll definitely update this post.

Enhanced by Zemanta

Wednesday, December 2, 2009

Mac Gems I’m thankful for

Macworld Expo Celebrity ChecklistImage by insidetwit via Flickr

Mac Gems I’m thankful for

Here's an extract from an article on MacWorld I found very useful since I use mostly


Source: macworld.com

It’s Thanksgiving day here in the U.S., and I want to wish all our U.S. readers a happy holiday. Since Thanksgiving falls on a Thursday, which is also a Mac Gems day on the Macworld calendar, I thought I’d mention a few Gems I’m thankful for—the inexpensive apps and utilities that I use every day to increase my productivity and generally make my Mac-using life a bit better.

This isn’t a list of our all-time favorite Gems; we published the most-recent version of that list back in June (although some of those products appear on this list, as well). Nor is it a list of my favorite Gems of 2009; you’ll see that one the week we publish our annual Eddy Awards. Rather, this is a list of Gems that I continue to use every day—Gems that have become such an integral part of my workflow that I often take them for granted.


To the developers of these programs, and of the many other great-but-inexpensive software titles out there, thank you. The Mac experience is better because of you.

  1. DocumentPalette: I use DocumentPalette many times each day to create a new document in the current folder via a keyboard shortcut—I just choose the type of document from the palette that appears.

  2. Dropbox: Over the years, I’ve tried many methods for keeping particular files in sync between my computers, and for sharing files with friends and family. Dropbox, with its Finder integration and automatic syncing, makes it easy.

  3. FlexCal: Flexcal lets me create new iCal (or BusyCal) events without having to open my calendar program. I just press a keyboard shortcut and provide the event details.

  4. Growl: More and more of my favorite programs take adantage of Growl to provide notifications and updates. Throw in HardwareGrower, a Growl add-on that informs me of hardware and network connections and disconnections, and my Mac feels lacking without this utility.

  5. Jumpcut: As a writer, I consider a multiple-Clipboard utility to be a must, and Jumpcut remains my personal favorite for its ease of use and elegant interface.

  6. LaunchBar: Jason Snell put it best: “If I could have only one Mac utility, a solitary piece of software that I could use to improve using my Mac and all its programs as I went about my daily business, it would be Objective Development’s LaunchBar. When I use a Mac that doesn’t have LaunchBar running, I simply feel naked.”

  7. MagiCal: Snow Leopard finally lets you put the date in the menu bar, but I still prefer MagiCal, which instead uses a tiny calendar icon for the date; clicking on the icon displays a useful monthly calendar.

  8. Mercury Mover: Among this add-on’s many features, the one I use the most is the capability to quickly restore windows to particular sizes and positions. For example, by pressing Mercury Mover’s keyboard shortcut followed by S, my Safari window is instantly placed in my favorite location with my favorite dimensions.

  9. MondoMouse: I use MondoMouse dozens of times each day to move and resize windows without having to grab a thin title bar or a tiny resize box—heck, without even having to click a mouse button.

  10. ScreenSharingMenulet: Using OS X’s Screen Sharing feature between my Macs has become a regular part of my daily routine, and ScreenSharingMenulet has made making those Screen Sharing connections simple.

  11. Sharpshooter: Tech writers take screenshots—lots of screenshots. When I choose to use Mac OS X’s built-in screenshot features, Sharpshooter lets me choose, on the fly, the screenshot format, name, and save location.

  12. Shimo: Mac OS X’s built-in VPN functionality doesn’t hold a candle to Shimo, which provides more features, more-reliable connections, and many automation options. It’s also a much-improved alternative to Cisco’s OS X VPN software. Did I mention it provides Growl notifications?

  13. SuperDuper: I’m paranoid about data loss, so I have a rigorous backup routine. Part of that routine is to use SuperDuper to schedule six clone operations every day—two each of three different drives. If a drive dies, I can be back up and running without much delay.

  14. TextExpander: In my line of work, a text-expansion utility—which automatically pastes frequently used text whenever I type a corresponding abbreviation—is up there with multiple Clipboards in terms of productivity gains. And TextExpander is my current favorite. According to the program’s own tally, I’ve expanded over 5500 snippets over the past couple years.

  15. Today: Today shows me the day’s events and tasks in a space-saving window, even if iCal or BusyCal is closed.

  16. Witch: OS X lets you switch between windows in the current program by pressing Command+`. Witch puts that feature to shame by displaying a list of every window in every application, letting you easily switch to—or act on—any of them.

There are plenty of other Gems that I use regularly, but these see daily action on my Mac and have worked their way into my routines. What are your most-used—and most overlooked—Mac Gems? Let us know in the comments. And if you're celebrating today, have a great Thanksgiving, and thanks for reading.



Reblog this post [with Zemanta]