Safari Open Tabs

Sharing and discussing custom actions for LaunchBar
Post Reply
xmanu
Posts: 14
Joined: Sun Apr 13, 2014 11:20 pm

Safari Open Tabs

Post by xmanu » Sun Apr 13, 2014 11:25 pm

This simple action searches all Safari windows for open tabs and displays them. Choosing one tab will activate Safari and the tab you chose.
Access the action by pressing right-arrow on Safari in LaunchBar (or type Safari Tabs).

I really hope this gets introduced in core LaunchBar, because I think this is really useful (and goes along well with iCloud Tabs).

Download here : http://manuel.weiel.eu/private-projects/launchbar-actions/
Last edited by xmanu on Tue Jun 17, 2014 6:46 pm, edited 2 times in total.

beejay
Rank 2
Rank 2
Posts: 54
Joined: Thu Dec 28, 2006 9:40 pm

Re: Safari Open Tabs (LaunchBar 6 beta)

Post by beejay » Sun Apr 20, 2014 10:30 pm

Hey thanks for this - this is really useful! :)

veke71
Rank 2
Rank 2
Posts: 62
Joined: Sun Jul 03, 2011 10:14 pm

Re: Safari Open Tabs (LaunchBar 6 beta)

Post by veke71 » Tue May 06, 2014 1:35 pm

nice one! I really really like LB6.

Jono
Rank 4
Rank 4
Posts: 161
Joined: Mon Feb 25, 2008 11:25 am
Location: UK
Contact:

Re: Safari Open Tabs (LaunchBar 6 beta)

Post by Jono » Thu May 22, 2014 2:24 pm

Very useful, thanks!

robbchadwick
Posts: 6
Joined: Sun Jun 29, 2014 3:40 pm

Re: Safari Open Tabs

Post by robbchadwick » Sat Jul 05, 2014 7:55 pm

Hello,

I've been using the Safari Open Tabs action with LaunchBar 6; and it was working beautifully ... a very handy action. However, since the latest update, I am getting an error. I've deleted the action & re-installed it with the same result. Has anyone else had this issue?

Also, since I'm a newbie at LaunchBar actions, do they update automatically (like Safari extensions) or do you have to look for a later version?

Thanks

hlissner
Rank 2
Rank 2
Posts: 42
Joined: Mon Jun 16, 2014 6:06 am
Location: Toronto, ON
Contact:

Re: Safari Open Tabs

Post by hlissner » Mon Jul 07, 2014 10:54 pm

robbchadwick wrote:Also, since I'm a newbie at LaunchBar actions, do they update automatically (like Safari extensions) or do you have to look for a later version?


No, there is no auto-update mechanism for actions, you have to look for them.

dnb
Posts: 2
Joined: Mon Jun 30, 2014 6:38 pm

Re: Safari Open Tabs

Post by dnb » Fri Aug 01, 2014 7:20 am

I'd really, really like to get this action working so I dug a bit deeper today (and also emailed the author).

The short version is the AppleScript is failing because it queries Safari for all tabs in all windows. Sometimes it gets back tabs that don't have a URL assigned to them (one way this seems to happen is if you quit and restart Safari. When the tabs are reloaded they have names but no URL assigned to them until they are re-activated. I think these are the ones in windows marked "Untitled"). Sometimes it also gets back windows without names or real data like an index.

When it goes to loop over each of these tabs, it attempts to convert the URL for the window into a string for use as a subtitle for LaunchBar. If the URL is empty (which I think is maybe a "missing item"), it fails to coerce the empty item into a string and throws the error you see in your console. It will also fail in cases where the window doesn't have an index. Specifically the line that is failing is here:

Code: Select all

set rtnVal to rtnVal & {{title:(name of t as string), action:"selectTab", actionArgument:(id of win as string) & "." & (index of t as string)}}


As far as I can tell, all that is needed to fix this action is to change the AS so it doesn't try to coerce these empty values into strings (and skips over windows without an index).

Unfortunately, the last time I really played with AS in earnest was back in the QuickKeys days for OS9 (so maybe 20 yrs ago) so I'm a little, um rusty. I can try to spin back up on AS syntax and control flow again but I would love it if someone who already knows AS can beat me to it and add the one or two lines that would do the right thing.

-- dNb

dnb
Posts: 2
Joined: Mon Jun 30, 2014 6:38 pm

Re: Safari Open Tabs

Post by dnb » Fri Aug 01, 2014 8:26 am

Ok, I have a solution which I'm not particularly proud of, but works fine. Basically if you surround the line above with "try" and "end try" it catches the errors thrown and the action works.

Here's a recipe for getting this working:

  • download the file from the author's website above. Chances are when you download it, you'll get a single file which is not in the bundle format you can edit.
  • to get it into bundle format, from a terminal, unzip the file you downloaded. You'll find you now have what looks like two files (Safari-Tabs.lbaction and Safari Tabs.lbaction). The one without the hyphen is the bundle we'll be working with.
  • from the Finder, right-click on the one without the hyphen (the bundle we just created) and choose Show Package Contents. Keep on opening folders until you get to Scripts which has a single file called 'default.scpt. Double click on it to open it in the AppleScript editor.
  • right before the line that starts "set rtnVal" add a new line that says "try". Right after the line that begins with double dashes, add a new line that says "end try". It will look like this when you are done:

    Code: Select all

    try
    set rtnVal to rtnVal & {{title:(name of t as string), subtitle:(URL of t as string), action:"selectTab", actionArgument:(id of win as string) & "." & (index of t as string)}}
    --display dialog name of t as string
    end try
  • Choose File->Export. Turn off "hide file extension" and replace the file with your new copy.
  • Go back to the folder where the bundle lives (back button in finder until you get there). Click on the bundle and let LB6 install it for you.

and win!

Actually, one more step. This action needs LaunchBar to be authorized to have Accessibility control. To do this, go to Apple -> System Preferences -> Security & Privacy. Unlock the lock on the bottom, and the select Launchbar from the list above if it isn't already selected.

Now win!

-- dNb

xmanu
Posts: 14
Joined: Sun Apr 13, 2014 11:20 pm

Re: Safari Open Tabs

Post by xmanu » Fri Aug 01, 2014 10:20 am

Thanks very much for the possible solution. As I currently do not see a better solution, I did include it in the Action and I released version 1.4.

robbchadwick
Posts: 6
Joined: Sun Jun 29, 2014 3:40 pm

Re: Safari Open Tabs

Post by robbchadwick » Fri Aug 01, 2014 12:39 pm

Thanks to all for your work on this. I installed the latest version & it works fine.

Post Reply