Friday, February 29, 2008

How To: Re-open Closed Tabs in Camino & Safari with AppleScript

Rather than update my previous entry on this topic I decided to write a new one since much has changed.

First I'd like to acknowledge Lisa Thompson for her AppleScript expertise, and code contributions. I have adjusted my scripts to use some of her ideas, with permission. As well, Lisa has some excellent AppleScripts for Camino, including her own rendition of the scripts you'll find here. While I lean more toward keyboard shortcuts and apps like FastScripts, Lisa looks to use a new feature in Camino 1.6 - that of adding scripts to the toolbar menu. (note that my scripts can also be used in the toolbar, but mine also tend to have a bit more stuff - relating to keeping certain windows open, etc.).

If you are a user of FastScripts, iKey, Keyboard Maestro, etc., and you like to launch scripts with keyboard shortcuts, you'll find these scripts handy.

Objective: To give Camino and Safari the functionality of automatically saving the current URL of a tab, writing that URL to file for later retrieval, if desired. If the tab was closed accidentally, using the second script, one can reopen that URL in a new tab.
(
Note: Saft already provides this functionality in Safari; Saft costs $12. In addition to reopening closed tabs, Saft also retains the history of said tab. These scripts do not retain the history of the closed tab, merely the URL of the tab at the time it was closed. To my knowledge, nothing like this exists as a plug-in on Camino.)

(Note: The "Save|CloseTab" and "Save|Prevent|CloseTab" scripts save ONE URL at a time. So if you want to go back to a tab you closed earlier, but have open/closed tabs since, these will not work - yet. I am looking at the possibilities of implementing that down the road.)

Background: Why did I do this? As a heavy-duty user of Firefox, I rely heavily on the Tab Mix Plus plug-in which retains tabs (with history), freezes tabs, and much more. But Firefox can get bogged down over time, or sometimes I just want to change browsers for a while. Whenever I switched to Camino for a breather I was amazed at the speed difference, yet discouraged at the lack of Firefox-like plug-ins (specifically Tab Mix Plus - hereafter "TM+").

So a few weeks back I decided to write an AppleScript a solution. I have found it so useful that I thought to share it with others. Perhaps these will be of help to you as well.

(Note: Very important to understand that these scripts do not help if you use the close button located on the actual tab, or if you take your mouse up to "File > Close Tab" or "File > Close Window" - those actions circumvent the AppleScripts).

Usage: When I'm browsing and close a tab (using Command W) that I wish to reopen, I simply hit Command F12 to reopen it. Why Command F12? Simply because it's the default key combo used in TM+. You can use something else if you prefer.

The CloseTab scripts are editable, once open, you'll see my notes as to what/where.

BOTH Save|CloseTab scripts will create a file in the root of the Sites folder. Camino's file is "UndoCloseTab-CAM.txt", Safari's is "UndoCloseTab-SAF.txt". Those text files will open/close automatically when called - you won't see anything, it's all in the background.

HOW-TO:

1) Put the AppleScripts in the folder of your choosing (For FastScripts, use the FS menu, Open Scripts Folder. Inside Applications, if not already there, create a "Camino" and/or "Safari" folder and place the scripts in the appropriate folder(s).
2) Open FastScripts (or your app of choice) and assign the key combo of "Command W" to the "CAM•Save|CloseTab" or "SAF•Save|CloseTab" script (or to the "Save|Prevent|CloseTab" scripts).

(Note: You'll want to assign keystrokes to a specific application. FastScripts, QuicKeys X, Keyboard Maestro, iKey can all do this. Make sure you're not assigning "Command W" as a global command, otherwise that combo will break in other apps. So just assign it to Camino or Safari.)

3) While in FastScripts, assign Command F12 (or other combo) to the "CAM•UndoCloseTab" or "SAF•UndoCloseTab" script.

There are more specific editing instructions in the CAM/SAF UndoCloseTab scripts.

Camino Scripts: (these scripts are for Camino 1.6)

1) "CAM•Save|CloseTab" (only saves/closes tab, does not prevent particular tabs from closing)

2) "CAM•Save|Prevent|CloseTab" (this saves tab URL, looks for page title of user-specified page and prevents closure of said tab, and also prevents last tab from closing)

3) "CAM•UndoCloseTab" (does what the name says)

Safari Scripts:

1) "SAF•Save|CloseTab" (only saves/closes tab, does not prevent particular tabs from closing)

2) "SAF•Save|Prevent|CloseTab" (this saves tab URL, looks for page title of user-specified page and prevents closure of said tab, and also prevents last tab from closing)

3) "SAF•UndoCloseTab" (does what the name says)

That's it. Enjoy browsing with a little safety net below ya. :-)

If you're an AppleScript guru and have suggestions, I'm all ears, so please drop a note in the comments.

Monday, February 18, 2008

Camino, Safari - How-To: Reopen Closed Tabs (with AppleScript)

Firefox has been my browser of choice for many reasons. First up on the list would be add-ons. I run several extensions, but my favorite - by far - is Tab Mix Plus. It allows you to freeze a tab preventing it's accidental closure. If you happen to close a tab and want to reopen it, you can - complete with the tabs history in tact.

But Firefox has its own quibbles. Tab Mix Plus can slow things down a little GUI-wise. At least that's been my perception. And Firefox is not exactly Mac like. Firefox 3 is looking great; however, AppleScript is not working as well in 3 - and if you know a fix for getting the URL of an existing page, I'd be most appreciative.

This used to work:

tell application "Firefox"
set Link to «class curl» of front window
set theTitle to «class pTit» of front window
end tell

Neither the «class curl» or «class pTit» work in FF3.

So on to Camino - it is awesome, faster than Firefox, but is not expandable with add-ons in the same manner that Firefox is. Tab Mix Plus is sadly missing.

So I put my brain to work and came up with a partial solution. I say partial because I cannot restore the history of a reopened tab, and these scripts can only restore the immediate last closed tab, not the last several tabs as in TMPlus.

These scripts work with Camino 1.5, but will need modification to work with v. 1.6 - which I do not have installed. Will update when 1.6 is out of beta.

I use the scripts in conjunction with FastScripts assigning the script the CMD-W keystroke overriding Camino's cmd-w. So when you use "cmd-w" to close a window, the script runs, copies the URL of the current tab to the clipboard. If you want to reopen the closed tab, hit "cmd-F12" or whatever key combo you assign and presto, it reopens (NOTE: if you have copied something to the clipboard AFTER you closed the tab, this won't work - this solution is for an "oops, I didn't mean to close that window" type of scenario! Also of note, this will NOT work if you use the close tab button.).

Here's the CMD-W script - I call this script "CAM-CloseTab(CmdW)", assigned keystroke "Cmd W" in FastScripts:

------- Script cut/paste below into new script ---------
tell application "Camino"
activate
set Remember to URL of window 1 (* Camino 1.5 *)
set the clipboard to Remember
(* BELOW - is if you have a site(s) you want to prevent from closing - replace XYZ with the TITLE or part of the TITLE of the page. Thus when you click Cmd-W, this site will not close *)
if name of front window contains "XYZ" or name of front window contains "XYZ" then
tell application "Camino" to activate
else
my closeTab()
end if
end tell

(* Tab Handler *)
on closeTab()
tell application "System Events"
tell process "Camino"
click menu item "Close Tab" of menu "File" of menu bar item "File" of menu bar 1
end tell
end tell
end closeTab
-----End Script----

Here's the Reopen closed tab script - I call it "UNDO Close Tab", assigned keystroke "cmd-F12" in FastScripts:

tell application "Camino"
set Remember to the clipboard
open url Remember (* Camino 1.5 *)
end tell

It is worth noting that some of this syntax will change with Camino 1.6.

This can be done with Safari as well, here's the scripts:

Assigned in FastScripts as "Command W":

tell application "Safari"
activate
set Remember to URL of document 1
set the clipboard to Remember
if name of window 1 contains "XYZ" or name of window 1 contains "XYZ" then
activate
else
close current tab of window 1
end if
end tell

Reopen closed tab (assigned in FastScripts as cmd-F12 keys):

tell application "Safari"
set Remember to the clipboard
open location Remember
end tell

If you see something that could use tweaking or such, drop me a note in the comments.

Thursday, November 08, 2007

10.5 Gripe: Finder QuickTime Controls Gone?

In Tiger (and prior iterations if memory serves) we had the ability to play Audio/Visual material within the Finder - MP3s, movie files, etc.

There was the customary QuickTime bar with the volume slider on the left, next the play/pause button as the graphic shows.



But Apple has decided in their infinite wisdom to take that away from us in Leopard.

Here's a screen shot of a generic MP3 preview in Leopard's Finder (Column View), and one with album art:











Sure we have Quick Look with the ability to play/pause, we have Cover Flow, too ... but why take away simple volume control and leave only the play/stop button?

So in order to control the volume of a file I want to play *w/o opening iTunes* I have to do finger gymnastics on my PowerBook (due to scripts and such I have volume, brightness, etc., using the Fn key with a corresponding F key) - or use the volume slider on the menu bar. But I do not want to turn down the system-wide volume - I need it for other alerts. I want to have more granular control back over individual A/V files in the Finder. Pointless to remove it, Apple.

While the new functionality/album art preview may be eye candy, it fails on functionality. May seem insignificant to some, but it was like a "Quick Look" or "Quick Listen" in Tiger without having to open iTunes.

Is there a way to get the "old" way back in Leopard?

Wednesday, November 07, 2007

Leopard Quick Look Tip: Increase Viewing Size of PDFs

Quick Look is somewhat of a mixed "blessing" in Leopard.

Some items are simply too small or small enough to be an eye-strain - such as Word, Excel, documents, etc.

I was viewing a PDF and on a whim decided to try "Command +" and voi la, the text size increased accordingly.

"Command -" will decrease it.

Unfortunately I've not found this to work with anything else.

As well, I cannot do a Quick Look of Pages documents? Only see the Pages icon.

I'm still using Pages 1.0.2, so I cannot say if newer versions allow for Quick Look.

Anyone have the newer versions? Can you Quick Look contents?

Thursday, November 01, 2007

Leopard: CAPS anomaly fixed

UPDATE: It occurred to me that I had installed TypeIt4Me 3.2 this morning ... I feel like a jerk, but perhaps my faux pa will help someone else. A new feature in TypeIt4Me is "No DOuble CAps". Of course I assumed this was after an expansion, not in the typing of the expansion. Alas, it is in the typing, thus it has fuddled up CAPS in every app. Until I turned it off.

So this entry has turned into a TIP - if your attempts to type words in CAPS is failing, and you have TypeIt4Me 3.2 installed, UNcheck the "No DOuble CAps" option. :-)

Old entry below.

I deserve any frustrations at this point that I get from Leopard for being an early adopter. I know better. But I couldn't resist. Like the monkey getting his fist caught in a jar, here am I, caught with weird issues.

Suffice it to say, I've not had a blue-screen crash, but I have seen the Finder ... or some service fall to its knees a few times requiring a reboot. Odd thing here is that "Force Quit" has not worked much. Those apps I try to FQ kind of look at me and say "yeah, so what?" turn and ignore me.

The real fly in the ointment right now, as odd as this may seem, is typing and using the shift key. This has become a royal pain in the butt. Why? I'm a fairly speedy typer and make a lot of use of the shift key - not just at the beginning of sentences or when typing proper names, but when typing abbreviations like "PDF' (which I suppose is proper), or "GPS", or to CAP a word for emphasis.

In Tiger, and in XP, and in Vista, and in every other OS, and on every typewriter I know of, when you hold down the shift key, every letter you type will be in CAPS until you let go (assuming you've not pressed the CAPS LOCK key).

But not in Leopard. I only get the first letter in Caps ... if I hold shift down (like now) to type "GPS" I get "Gps" - you see, only the G is in CAPs.

So I figure letting go of Shift for the next letter, then quickly pressing before I type it will give me a capital P... but no. It is still lower case. Repeating that will sometimes give me a capital "P".

Same thing goes with punctuation. I type two quotes in a row and I get "' - not always, but enough that my typing speed is no longer in the 80+ wpm range.

I've looked at the keyboard prefs, and anywhere else I can think of, but I come up zeros.

Is anyone else having this problem? Occurs on my system in every single app - even here in Firefox as I write this entry. Happens in text input dialog boxes from AppleScript, you name it, it happens.

Apple cannot release a 10.5.x upgrade fast enough in my book.

In case you were wondering, I did an Erase and Install, then selectively restored my data (not using a backup program) as well as selectively copying or installing applications from backup or a new .dmg.

Monday, March 26, 2007

A Better Mouse Driver: SteerMouse

SteerMouse is an alternative, fully-customizable application/driver for your USB or Bluetooth mouse.

Price: $20 shareware, 30 days to try

I'm using SteerMouse with a Logitech VX Revolution.

The included software with the Logitech VX Rev., is a joke. Logitech should be ashamed to put out such a second-rate app with such good mice. They should fix their software or consider bundling SteerMouse with their mice. Attempting to use Logitech's software was a comedy of errors and resulted in erratic mouse behavior, not to mention the lack of button customization.

Using the built-in mouse driver for OS X was not an option with this mouse. With other simple mice, OS X's driver worked fine, but the form factor of the VX Rev was a perfect fit for my hand, and small enough to use on the palm rest on my PowerBook. I was not going to return the mouse just because Logitech's driver was terrible, and OS X's wouldn't work.

So after some digging I came across SteerMouse and promptly downloaded a 30 day trial from MacUpdate. I couldn't have been happier. Out of the .dmg "box" SteerMouse worked like a champ.

Installation is simple and smooth.



Once your Mac has rebooted, simply go to the System Preferences app, look under "Other" (bottom section) and look for the SteerMouse icon. It is a yellow "bumper-car" looking mouse.





Clicking the icon opens a separate SteerMouse (hereafter, "SM") application. This behavior of having a launcher of sorts in System Preferences is similar to Microsoft, USB Overdrive, etc.

Below are screenshots of each tab in the SM application.



A note here, as you look at the image above, you'll see the pull-down menu which shows "Default". Pulling it down shows the following screen shot (w/out the additonal apps until you add them).



This menu is where you'll find the option to "Add/Remove" individual apps and tweak some or all mouse settings in the chosen app. I changed settings for certain actions in BBEdit that I did not wish to take place in all apps. Additionally, I set up specific keystrokes when in Firefox, Safari, or Camino.

Thus each mouse button can be customized. When clicking the elongated button associated with a particular mouse button, you see the following pop-up menu:



Input Shortcut Key allows you to set the particular button with a key command - it could be any key on the keyboard or a combination there of. Modifiers can also be used: command, shift, option or control keys.

Scroll Action lets you assign the scrolling speed to a button.

Cursor Action will move the cursor to the blinking button, or just about any other button including the close, minimize, zoom, Apple menu, etc.

Switch Application performs the Apple + TAB function.

Click Action is a mouse click, double click, triple click, click lock, contextual menu, middle or default click PLUS use of a modifier key (command, shift, option, control) if desired.

Change Cursor Speed allows you to either increase or decrease cursor speed

Open allows you to either open a file or folder, including an executable-upon-open file like an AppleScript application

No Action - disable a button altogether



Here you can tweak the acceleration when scrolling.



The Tilt Wheel settings were fine out of the box for me; however, one can get pretty granular in settings here.

And I should point out that when I tried USB Overdrive, oddly my right tilt would work only when I pressed hard right on the wheel to elicit the proper side-scrolling response. After switching to SM, this behavior went away and I only need a gentle right tilt and the response is immediate.



I do not use any automated pointer moving, so I set this to "None". As for tracking speed, this is a nicely customizable option for those who are switchers (or not) and desire faster mouse speeds from Windows days will enjoy the tweaking possibilities.

Conclusion:

SteerMouse came to my rescue and gave me full use of my VX Revolution, and is the only alternative mouse driver/app that gave me full use of every button on my mouse, including the "magnify" button behind the scroll wheel. Additonally, I found SteerMouse to have the best, smoothest scrolling/acceleration behavior.

For some the $20 price tag may be high, especially if an expensive mouse is part of the equation. But if you purchased a Logitech, Apple Mighty Mouse, or a Bluetooth mouse and love it but not the included software, or limited functionality, then this is $20 well spent.

Anyone looking for full functionality of their mouse should take a serious look at SteerMouse.

This is well-written software which, like Apple products, "just works".

Wednesday, January 03, 2007

Macworld 2007 - iTV, what it could be

Macworld 2007 is coming next week. Steve Jobs is slated to give keynote on the 9th. Going to be a humdinger if Apple's site is to be believed.

I am ready. Wow me, Apple. Go beyond the press hype. I hope you've sowed some disinformation out there that sounds incredible, but pales to what you'll actually unveil. Why misinformation? So I'm not depressed when the press once again over-hypes the event and I feel let down by the keynote because it didn't live up to expectations.

What will impress me? Well, a Mac Tablet of sorts, that'd be über-swell. iPhone/iMobile, or whatever iPod/phone/PDA combo would be fine, but I'm personally gung-ho for the tablet, whether it's a new convertible notebook or, better yet, designed like the iMac, an all-in-one unit. Go to town, Mr. Ives.

As for the expected: Leopard is coming, as well as iTV, the latter of which, only appeals to me on a wow-factor level. See, I pay a bundle price right now for cable - phone/internet/digital cable. That package includes a decent-but-no-TiVo DVR which does HDTV via HDMI. I pay a handsome ransom for that bundle and I don't really want to have to buy an Apple device that provides some of the same things, but does so from my Mac (which does not have a TV tuner by the way - what's up with that?) and not from the cable signal.

See, iTV is one of those areas where I hope to be super-wowed. It has to go beyond and provide me value that supersedes, not just compliments my cable company. If iTV is a one-time charge, and works seamlessly with all things, that's great. But I suspect the truth is more like Steve's teaser demo last year - I'll be purchasing movies/music/TV from the iTunes Store, a new Airport 802.11 N at an exorbitant price, and a larger hard drive to house all this digital information.

That's money I don't have. I did not join the iPod generation(s) but I have purchased from the iTunes Store - less than 100 songs, TV shows. Not sure where I'm going with that... I suppose I'm just trying to say that I've used and will continue to use the iTS for some things.

So to stray just a little, remember the call for a la carte cable? I think it's still on the table, but this is where you and I can purchase, say, PBS Kids, Discovery HD, CNN Headline News, Food Network, Animal Planet, Sci-Fi Channel, Spike, etc., individually as opposed to part of a package deal. We buy only the channels we want. I like this idea. I am pretty certain this idea is going to be more pricey than the package deals, but if it brings peace of mind and keeps out the stuff we don't want, then for some it will be worth the extra money.

The iTunes Store is sort-of like this, but more granular. It's a la cart for shows, and that's just too expensive. See, I'm thinking a la carte cable will be priced at $2-3 per month per channel, in addition to a basic cable charge. But I will get a full season of the now available ST: Voyager on Spike as opposed to plopping down $1.99 PER SHOW on iTS (huh, no Voyager on iTS? ... you get my point).

So if this is Apple's alternative with iTV, I'll not be too impressed. However, if all new Macs will have TV built in - with HDTV capabilities, please - then it is a different story. Try this: what if iTV will have either built-in or as an add on, the capability to broadcast your digital cable signal over the expensive Airport 802.11 N to your Macs (including the tablet) around your house. Now that would be cool. Include in each Mac with Leopard the ability to DVR, too. Now that is something that will trump all other cards including a no-show iPhone, IMHO. But once again, I think Wall St. and the iPod generations want the phone more than anything else.

And I suppose the regulations and hurdles Apple would have to jump through would make this nigh impossible. But just as the music companies are beginning to see the light, perhaps Apple will have the chutzpah to change TV as we know it like they changed tunes.

Ah, whatever. I'll probably nuke some popcorn and enjoy the show. I hope it's streamed live.