Archive for the ‘AppleScript’ Category

Distribute Files as a Quick Look “Show”

Wednesday, March 19th, 2008

QuickI was so close to making a screencast tonight, but the stuff I was looking at isn’t quite worth the time. For me. Maybe for you?

I found these little apps on Apple’s Applescript site that let you drop some files onto a droplet. The files are stored in the droplet which when double-clicked displays the files in Quick Look. So you could send the droplet to another Leopard user and they could see a group of photos, Numbers docs, or whatever mix of files you drop in there. As long as Quick Look can display them you’re good.

The downside is that it’s not really using Quick Look - the script utilizes qlmanage which is a Terminal utility intended for Quick Look testing. Unfortunately the command line version of Quick Look doesn’t do everything full-on Quick Look does. For example, once I invoked the Index view I couldn’t get back to regular view. I couldn’t go full screen. And the space bar wouldn’t close the Quick Look window. The site provides ample warning that qlmanage isn’t everything that Quick Look is. It does play video though.

On the plus side, it’s conveivable you might want a different look for files you’re distributing. A single Quicktime movie sent this way might get a little more attention, it won’t look like the same old same old. Then again, if it gets sent on to a non-Leopard user that wouldn’t be good.

Looking at the package contents (right click the droplet and select Show Package Contents) you’ll see that the underlying Applescript invokes qlmanage with the -p option, which displays normal Quick Look previews. I was hopeful when I saw the man page in Terminal. The -t option displays thumbnails, but not in the manner you might expect.  I expected the Quick Look Index view.

Altering the script to use -t resulted in thumbnails displayed one at a time in a Preview-looking window - revealing the next preview only when you close the previous one. It didn’t look like Quick Look at all.

If there were a way to make it open in Index view and have that view function like Quick Look - letting me get back to the default view - I’d be interested. But I’m not. What about you?

You can read more about the downloads here. The download includes another droplet for Quick Look that opens the files you drop on it immediately with pseudo Quick Look.   It uses qlmanage as well.

There’s another download on the site that lets you click a Finder toolbar button to jump into a full-size Finder window in Cover Flow view - with one click. Is that anything?

Fetch New Mail.app Messages from Your Phone

Thursday, March 13th, 2008

retrieve emailsThis post is intended for people with mobile phones that don’t have Internet access, but can receive emails in the form of text messages. You will also be interested in this post if you’ve had problems with Mail.app rules in Leopard.

Need to check for new messages in Mail.app from your stone-age mobile phone? No problem. Send yoursef an email with a preset subject like “MsgFetch” and your unread emails received that day will be forwarded to your phone. This way you don’t always forward to your phone, burning up all your text messages.

The script will append the sender name into the subject so it’s easy to glance at your phone and see who sent each message - since they’re all forwarded from your email address. The messages are marked as read in Mail.app so they won’t be resent if you issue another request later.

One more thing: This solution also gets around a problem with rules in Mail.app under Leopard. It seems that scripts called by a rule won’t generate a new mail message, which is something this script needs to do.

Instead of relying on the rules of Mail.app, the rule processing is baked into the Applescript. By setting the script to run on a periodic basis we can test for trigger emails in the inbox.

How do you get the script to run periodically? You can have iCal do it. Or you could use something like Lingon to configure launchd, which handles scheduled tasks in Leopard. This post has a screencast that covers Lingon.

You could also create a shell script that kicks off your Applescript, or a group of Applescripts for that matter. The shell script would look something like this:

osascript <path to script file>/ <script file>

or

osascript ~/Documents/scripts/mailforwarder.scpt

You can download the Applescript and read the in-line comments explaining how it works. But let’s take a quick look at two excerpts from the Applescript:

The first part of the script handles what a Mail.app rule would normally cover. Since rules aren’t working as expected the Applescript handles that duty by looking for an unread email with MsgFetch in the subject. If there is such a message the script calls a subroutine ( a chunk of script) called mail_forwarder.


The other part we’ll look at is located within the mail_forwarder subroutine. It finds the emails that arrived today. The next part, not shown here, checks to see if the message has been read.



The rest of the script has been covered in other Murphy Mac posts. It’s the part that creates and sends the mail message. Murphy’s posts on mailing files from Finder and retrieving files by email both create and send mail messages using Applescript. The Finder post has a screencast that goes with it.

Related posts:

Using Lingon

Creating a shell script

Other tricks with Mail: Pick a Playlist by Email - Retrieve a File by Email - Mail a File Dropped in a Finder Folder

Download Applescript

Retrieve a Remote File - by Email

Saturday, February 16th, 2008

zipIf you’re using an iPhone or a touch or some other mobile device this could be a very convenient way to retrieve a file from home and view it on your device.

Here’s the scenario: You’re on the bus, you realize your French homework is sitting at home on your Mac. Send yourself a text message with the path to the file. By the time you get to school and log on to a computer your file has been emailed. Problem solved.

Configure Murphy’s script to run every so often using something like launchd. Then send yourself an email. Include the path to the file you want sent in the body, like this:

/Users/murphy/Documents/PenskeFile.doc.

Mail will create a new message, attach the file, and send it to the address in the script. You can configure the script to run when a certain word is in the email subject, like FileGrab. This is an ideal use for rules in Mail.app. But rules don’t seem to work in Mail as of 10.5.1. Murphy hasn’t tried 10.5.2 yet.

Update:  If you leave the file name out the folder’s contents will be zipped and sent.

Instead of using rules, this script is written to run periodically. Maybe every ten minutes or so. If it sees an email with the keyword in the subject it checks for the file and sends it. If the file doesn’t exist the script sends an email that says so.

zip

Security hole? Well, Murphy doesn’t think so. The file will only be mailed to the address you specify in the script, it’s not a reply. (you could alter the script to have it reply, but that doesn’t seem like a good idea.) You can use secure email to send the request and the file. That’s secure.

Getting back to the mobile devices: Your unhacked iPhone and touch don’t let you download files. So you can’t SSH back to the house and grab the file. You could set up your Mac as a web server, but I wouldn’t want to do that.

Using this script the file is emailed to you, so you can view it in Mobile Mail or Gmail depending on what kind of file it is. You can easily view the file later, when you’re offline. The catch? You need to know the path to the file you’re retrieving. Don’t know the path? Here’s some help.

Windows Users: Have a look here.

Note: Script requires use of Mail.app. To schedule this script to run on a schedule you might want to try something like lingon for editing your launchd configuration.

Other Murphy scripts for working with Mail:

Sleep Your Mac by Email

Select a Playlist by Email

Get a List of Your Files by Email

Retrieve Mail.app Messages by Text Message (this post shows how to match emails with Applescript using multiple criteria)


Download Script

Select a Playlist by Email - And More

Sunday, February 3rd, 2008

Playlist by EmailI can see the comments now. “Why not just…” But let’s be patient and save judgements until you’ve read the whole post.

Yes, I know there are tons of ways to control iTunes from your iPhone or your touch or another computer or your fancy remote. (Murphy even dug up an old Pocket PC recently to try out Salling Clicker, which also supports BT phones) But there’s no harm in having yet another avenue for getting some music playing.

Murphy stumbled into a script that checks the content of an email for instructions on what to play in iTunes, like a playlist or an artist. But there’s more - just like the title of this post says. The script can also tell iTunes to play through external speakers via your Airport Express. That might not sound like much, but it is, because iTunes doesn’t provide the necessary hooks to control speaker selection. (more…)

Download Script

New and Improved: Finder Emailing

Thursday, June 28th, 2007

Murphy posted about emailing from Finder a while back. This new screencast was entered in the Macinstruct tutorial contest, winner to be announced next week.

Finder MailerJust drag a file to a folder and it flies off to a pre-determined email address. Optionally, have the action prompt you for a subject so you can find it later.

Murphy finds this technique extremely useful for quickly backing up important files to a dummy Gmail account - especially with the new 20MB attachment size. You have files you can’t bring yourself to delete? Drag them to the folder and they’re on their way to a mail server, just in case you want them later. No addressing, no need to click send. It’s just sent. Murphy knows you can drag files to the Mail icon in the Dock. This is more direct - no extra clicks!

If you’ve got multiple assistants you send files to all the time you could create a folder for each. Dragging a file to their folder is like dragging it to their inbox.

The new screencast details both a Folder Action and an Automator solution. They achieve the same thing in terms of sending. The difference is that the Automator method leaves the file in its original location on your disk, which might be more convenient. But the Folder Action method can be utilized from an SSH session. That opens up a lot of possibilities and offers extra convenience.

The Automator solution comes from a post on TUAW that was inspired by a post on MacOSXHints that was submitted by Murphy. How’s that for a chain of events?

Visit the previous post to download the AppleScripts used in the screencast.

Watch Now