An AppleScript to convert PDFs to Safari bookmarks
Copy the following AppleScript into Script Editor, and save as an application: on open pdfFiles tell application "Finder" repeat with pdfFile in pdfFiles set thedestination to folder of pdfFile set theName to displayed name of pdfFile -- convert pdf to base64 and copy result to clipboard do shell script "/usr/bin/perl -0777 -e 'use MIME::Base64; $text = <>; $text = encode_base64($text); $text =~ s/\s+//g; print "data:application/pdf;charset=utf-8;base64,$text\n";' < " & quoted form of POSIX path of pdfFile & " | pbcopy" set theurl to the clipboard make new internet location file to theurl at thedestination with properties {name:theName} end...
published on Thursday, the 31. July 2008, macosxhints
Easily add lyrics to iTunes songs via AppleScript
Often programs like PearLyrics or SingThatiTune just don't find the song I am looking for, and I have to find the lyrics manually. I found it tedious to find the lyrics in Safari, switch back to iTunes, highlight the song I want to add the lyrics to, open the song's info panel, paste in the lyrics, and finally, close the window. So I wrote this simple AppleScript instead: tell application "System Events" set sel to (the clipboard as text) end tell tell application "iTunes" set lyrics of current track to sel end tell I then bound this AppleScript to a keyboard shortcut using iKeys (any macro-capable program should work just as well). It will copy any text currently in the clipboard to the currently playing song's lyrics.
published on Wednesday, the 16. July 2008, macosxhints
Bypass DNS timeouts in Safari via AppleScript
For some reason, Apple has given Safari very little patience in waiting for DNS queries -- it quite often gives up on a query and won?t load a page, even though that page will load fine in Firefox or another browser. If you need to use Safari, though, you can use this script to look up the IP address of the site and load the page using that instead: (* Bypass DNS in current tab © RickoKid 2008 Version 0.1 This script was written to get around the annoying way that Safari gives up very easily when waiting for a DNS lookup, but command line DNS lookups still work fine. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as ...
published on Tuesday, the 20. May 2008, macosxhints
Use Script Editor to develop bookmarklets
If you're developing a non-trivial bookmarklet you may be able to speed up your edit cycle by having an applescript which executes the javascript in your browser, like this:tell application "Safari" activate do JavaScript " // Of course your bookmarklet code goes here, for example... alert('hello world'); " in front documentend tellI just edited the Javascript in Script Editor and hit the run button to test. Just be careful of using double quotes, and you can postpone escaping the script and adding it to your bookmarks until the very end.
published on Thursday, the 8. May 2008, macosxhints
View higher quality videos on YouTube
Many people are using a trick to view any YouTube video in high-quality -- simply append &fmt=18 to the end of the URL. This is a job for AppleScript! Here are two simple versions; the first, for for OmniWeb: tell application "OmniWeb" set current_url to the address of active tab of browser 1 set current_url to current_url & "&fmt=18" set the address of active tab of browser 1 to current_url end tell ...and the second, for Safari: tell application "Safari" set current_url to the URL of current tab of window 1 set current_url to current_url & "&fmt=18" set URL of current tab of window 1 to current_url end tell These can be placed in ~/Library » Scripts » Applications » AppName for easy access via the Script menu. [robg adds: Queue user fds suggests that a JavaScript bookmarklet may work better, and it will work in any browser. Create a new bookmark for any site (or a blank ...
published on Friday, the 21. March 2008, macosxhints
Start playing partially downloaded videos in VLC
I frequently download video files from a web server, and would like to start watching them before the download completes -- VLC, for one, can start playing a video while Safari downloads it. This AppleScript automates that task. Simply select the .download file in the Finder and run the script. You'll probably want to save this script as an Application Bundle: on run tell application "Finder" copy selection to fileName0 end tell set fileName to fileName0 as string if fileName ends with ".download" then set AppleScript's text item delimiters to ":" set listNames to text items of fileName set AppleScript's text item delimiters to "" set baseName to last item of ...
published on Thursday, the 6. March 2008, macosxhints
Fully automated, one-step sending of a URL from Safari
I often send a link off to one single person, many times a day. You can use the Mail Link to this Page feature in Safari, but that still means you have to compose the email with the To address, and also tell the email to send. Since I do this several times a day, I decided to AppleScript it. Drop the following script into ~/Library » Scripts » Safari; name it what you like. If that folder structure is not already made, just make new folders with the correct names. The script will get the current URL of the frontmost document in Safari. It will not copy it to the clipboard, leaving your clipboard in the same state. The script them brings Mail.app forward, addresses an email, sets a subject, some body copy, and drops the URL into the email. Finally, a signature is added to the message, and it is sent out. After that has happened, Mail.app is set to hidden, and Safari is brought back to the foreground where you last left it. Here's the script: ...
published on Friday, the 22. February 2008, macosxhints
Save selected browser text via AppleScript
I occasionally find myself wanting to save some text from a browser window. Usually I want to know where the text came from as well, so just dragging out a text clipping to the desktop is not a good solution. I wrote two AppleScripts (one for Safari and one for Firefox) to make saving a selected text, URL, and page title from browser windows easier. The scripts write the browser's selected text and other info to a text file that it creates on the user's desktop. (I don't like clutter on the desktop, so on my Mac, this file gets created in another folder. However, I wanted to provide example scripts that worked, so I chose the desktop). Below is an example of the script's output with the date, the URL, the page title and some text from a selection: Wednesday, February 6, 2008 8:40:11 PM http://some-url.com Photo of the Day ------------------- A deep-blue sky sets off a mass of yellow wildflower blooms along ... [snip] ... magazine ~~...
published on Friday, the 15. February 2008, macosxhints
Auto-fill FedEx forms in Safari via AppleScript
If you do a lot of shipping with FedEx, you know how annoying it is to cut and paste all the address information into Safari. There are expensive programs that will extract information, but most don't work with OS X or require Filemaker. Here's a quick hint I use quite often to autofill the FedEx forms. tell application "Safari" activate tell (make new document) to set URL to "https://www.fedex.com/ship/shipEntryAction.do?method=doInitialEntry&origincountry=us&locallang=en&urlparams=us&sType=&programIndicator=0" delay 2 set doc to document "FedEx | Ship Manager | Shipping" log (doc's name) do JavaScript "document.forms['domesticShipmentActionForm']['recipient.companyName'].value...
published on Thursday, the 14. February 2008, macosxhints
10.5: Put a Numbers chart on the Dashboard
I built a Numbers document to track my finances. One thing I added was a chart that allows me to see the balance in every account over time, plus my total worth. Wouldn't that be great to have that chart at my fingertips? Why, it'd be awesome to have that as a Dashboard widget. Numbers doesn't support this, and it has no AppleScript dictionary. Taking a screenshot won't do so great either, since I'd have to take it every time I updated the numbers. So here's what you do: Put your chart(s) on their own sheet. Save the workbook with that sheet active. Find the Numbers file using the Finder, control-click on it, and choose Show Package Contents from the pop-up menu. There will be a folder called QuickLook (see note). Inside that folder, there will be a jpg image file. Open that image file in Safari, and use the built-in...
published on Friday, the 8. February 2008, macosxhints