Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'Use AppleScript to select specific tabs in Safari 3' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Use AppleScript to select specific tabs in Safari 3
Authored by: bbeck13 on May 09, '08 06:45:24PM
I'm using this hint coupled with a trigger in quicksilver to emulate the firefox tab switching behavior for cmd-1 through cmd-9. Short video (not mine) about this here One problem I've noticed is that Quicksilver has a Leopard only bug that unfortunately makes the scope portion of a trigger not functional, so if you setup a trigger to these scripts, the trigger will fire not matter what application you're in. This is pretty easy to fix in the applescript itself so that's what I did. I'm not applescript expert, but here's what I did:

#!/usr/bin/env bash

SAFARI_SCRIPTS_PATH="$HOME/Library/Scripts/Applications/Safari"

mkdir -p "$SAFARI_SCRIPTS_PATH"

# tabs 1-9
for (( i = 1; i < 10; i++ )); do
script_filename="$SAFARI_SCRIPTS_PATH/Activate Tab $i"
osascript<<-EOF
  script setTab
    tell application "System Events"
      set app_name to name of the first process whose frontmost is true
    end tell
    
    if app_name is equal to "Safari" then
      tell front window of app "Safari" to set current tab to tab $i
    end if
  end script
  store script setTab in posix file "$script_filename" replacing yes
EOF
echo "Created $script_filename"
done

# last tab
script_filename="$SAFARI_SCRIPTS_PATH/Activate Last Tab"
osascript<<-EOF
  script setTab
    tell application "System Events"
      set app_name to name of the first process whose frontmost is true
    end tell
    
    if app_name is equal to "Safari" then
      tell front window of app "Safari" to set current tab to last tab
    end if
  end script
  store script setTab in posix file "$script_filename" replacing yes
EOF
echo "Created $script_filename"
echo "Done"


[ Reply to This | # ]