Automatically zoom new pages in Safari
Safari has a nice feature to zoom in (or out) on a webpage, which is great for large monitors. Unfortunately, you're not able to set a default zoom level for new pages. CSS hacks exist, but zooming via CSS doesn't seem to work as well as the native zoom function in Safari. The AppleScript in this hint zooms in on any new web page using Safari's own zoom function. The script is quite a hack -- it checks every tenth of a second to see if the currently active tab isn't zoomed in. If it's not zoomed in, the script activates the corresponding keyboard shortcuts to zoom the page. You can edit the script to change how often the zoom-check should be made, and what level of zoom should be made. repeat try -- we have...
published on Wednesday, the 20. January 2010, macosxhints
10.6: Create iCal event from dates in Safari
I sometimes want to create an event in iCal from a date that appears on a web page I'm viewing in Safari. Using Automator, I created a Service to do just that. Here's how: Launch Automator Select Service from the Choose a Template for your Workflow sheet. Set the drop-downs at the top of the Untitled service to 'Service receives selected' [dates] 'in' [Safari]. Drag a Run AppleScript action to the top of the Untitled service. Replace the template text in the Run AppleScript action with the following: on run {input, parameters} set eventDate to date (input as text) tell application "Safari" set currentTab to current tab of first window set event...
published on Monday, the 12. October 2009, macosxhints
10.6: Create a tri.im URL shortening Service
One of the great new features of Snow Leopard is the ability thru Automator (and by extension, AppleScript) to make your own service. Automator can set-up services to accept specific inputs (ie files, images, or text) to act on. If you have selected the appropriate type of input, the service will show up in your context menu.To create a service which generates a tr.im shortened URL when control-clicking a link in Safari. First, open Automator, and select Create a New Service. Set the Service to receive selected text in Safari.Find Run AppleScript from the Action library on the left, and drag that over to the right half of the Automator window. In that area, paste in the following:
published on Monday, the 14. September 2009, macosxhints
Create a Numbers document listing all Safari bookmarks
You might find this AppleScript interesting and/or useful -- it opens a spreadsheet in Numbers of all of your Safari bookmarks. set the bookmarks_folderpath to the POSIX path of (path to "cach" from user domain) & "Metadata/Safari/Bookmarks/" tell application "System Events" set these_bookmark_filepaths to the POSIX path of every disk item of folder bookmarks_folderpath whose name extension is "webbookmark" -- generate book mark AppleScript list: {{bookmark 1 name, bookmark 1 URL}, {bookmark 1 name, bookmark 1 URL}, etc.} set the bookmarks_list to {} repeat with i from 1 to the count of these_bookmark_filepaths set this_bookmark_path to item i of these_bookmark_filepaths tell property list file th...
published on Monday, the 15. June 2009, macosxhints
Reload Safari tabs in the background via AppleScript
I frequently have multiple Safari tabs open. I'll be viewing a site, and one of the other tabs is a site I've already viewed, but will want to view again after some time has passed and it's been updated. It is possible to keep a tab in the background and reload it by right-clicking and selecting Reload Tab, but that seemed inefficient and like an interruption to whatever content I was currently viewing.A quick trip into Applescript and I came up with this script to reload the first tab in the background:tell application "Safari" set sameURL to URL of tab 1 of front window set URL of tab 1 of front window to sameURLend tellA few notes:This script requires a launcher (Script Menu, Butler, Keyboard Maestro, Spark, etc.) to allow execution via the keyboard.I made three of these scripts, one for each of the first three tabs in a window. The tab 1 in the script reflects the first (left-most) tab. Make as many versions as you'd li...
published on Thursday, the 28. May 2009, macosxhints
Fix a conflict between ClickToFlash and PandoraJam
The ClickToFlash plug-in for Safari (recently hinted here) has an unwelcome side effect: it breaks the application PandoraJam, because PandoraJam uses WebKit and Flash to build its interaction window. I wrote an AppleScript that works around this problem by deactivating ClickToFlash just long enough to launch PandoraJam, then reactivating ClickToFlash. Here's the code: --PandoraJam Launcher 1.04 --Mar 10, 2009 4:08 AM --© Jeff Porten 2009 --Latest version here: http://www.jeffporten.com/?p=9... --Donations...
published on Friday, the 27. March 2009, macosxhints
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