Capture all tabs in Safari as URLs to the clipboard

Sometimes you’re doing research and have a pile of tabs (and windows) open and need to get them into a document to share with coworkers… so I went digging and tweaking and found an Applescript that does the job:

tell application “Safari”
set docText to “”
set windowCount to count (every window where visible is true)
repeat with x from 1 to windowCount
set tabCount to number of tabs in window x
repeat with y from 1 to tabCount
set tabName to name of tab y of window x
set tabURL to URL of tab y of window x as string
set docText to docText & tabName & ” – ” & tabURL & linefeed as string
end repeat
set the clipboard to the docText
end repeat
end tell

You can save it as a standalone script and run it from there, or stick into a script item in Automator and run it as a service.. or even call it from the command line as an Osascript.

Desktop Pictures & Automator!

Some people call them wallpapers, I prefer desktop pictures… and I have a big collection of them. hmm. 336 of them in the current rotation, as of this article. I’ve been collecting them for at least a decade, according to the earliest modified date.

b45cc436ed2f93304aa23a7d59

So what do I do with them, and where do I find them? Well, currently I have them all in a folder in my Pictures folder, aptly named Wallpapers. Yeah, I wanted a short name! They come from various sources, but the main one is http://www.desktoppr.co/ What’s so good about that site? Well, it’s linked directly into my Dropbox folder, so syncing an image is as simple as clicking the little cloud icon under the image. Very nice feature. They all end up in ~/Dropbox/apps/Desktoppr/ which, as you may have noted, is not where I keep my collection.

drxfh-2012-12-03-0206

Why not, you ask? Because there are many images that are in my collection that are personal photos, and I do not want to make them part of my Desktoppr library. You guessed it, anything I add to the Desktoppr folder goes back up to the site. You can see my collection online, once you login, at https://www.desktoppr.co/theconsultant

972fa8304265c4528873d40eac

For a while I would sync new images to Dropbox, then manually copy them across to the Wallpapers folder. This got tedious fast, so I worked for a while on cobbling a bit of a folder action script together. After messing around in Applescript for a day and not quite getting what I wanted, I headed over to Automator.

wallpaper-2481554-2012-12-28-0213

I created a new folder action and added the “Copy Finder Items” and chose my Wallpapers folder. Umm, that’s it. Too easy. Saved it, and then right click the Desktoppr folder and, in Services, go into Folder Actions, and add the workflow.

20410cc7eda936b47f103458df

Next time an image dropped into the Desktoppr folder it automagically got copied across. No more manual syncing.

Now I can spend all that extra time looking for the next great desktop picture!

b0bc3145225d99db362c014177

Controlling iTunes from the command line

I had a little fun the other day, making a script that would pause iTunes, from the command line. In the end I made ones to pause, play, and go forward a track.

All of them use a slightly modified version of a line of Applescript:

tell application “iTunes” to play

You can also tell it “to next track, to pause, to stop, to previous track”, which all work as expected.

To get it to work on the command line you’ll need to turn it into a script, which is a plain text file with some command line options in it. To get Applescript to work on the command line we need to use osascript, with the “-e” option.

Here’s what you should have in your file:

#!/bin/bash
osascript -e “Tell application “iTunes” to pause”

Note the the quotes and slashes? You need to wrap the Applescript command in quotes, and since you have quotes in the middle of it, you need to escape them using the slashes so the whole applescript is parsed.

Next step is to save the script to somewhere useful. In my case I have set my command line environment to check for scripts in ~/bin/ , so I saved it there as ‘pause’. After that you will need to make it an executable, so pop into the terminal and do “chmod +x ~/path-to-your-file/pause”, at which point you run it.

Go play something in iTunes, and then go over to the Terminal and type “pause” and hit enter. If your script is in your environment path then iTunes just paused…

Here are the other scripts I used, just to make your life easier 😉

#!/bin/bash
osascript -e “Tell application “iTunes” to play”

#!/bin/bash
osascript -e “Tell application “iTunes” to next track”

Feedback is appreciated!