Skip navigation.

exploreopera

| Help

Sign up | Help

photo

Introvertio

all systems nominal

AppleScript support in Opera 9.5

, , ,

Noting the AppleScript support in Kestrel 9.50 beta, it is prime time to update some scripts! To do some testing, let's start with adding support for Opera to TextMate’s HTML bundle. You can tweak the bundles using TextMate's built-in Bundle Editor.

Kestrel's AppleScript dictionary didn't get registered by default. In order to inspect it, hit Open Dictionary... on Script Editor menu and choose Browse... to pick the Opera application. It's up to you to explore the details yourself. I noticed that some kind of reload function i was after is missing. Furthermore, while a specific window can be targeted by calling its index number, there is no way to address individual tabs.

Let's expand the HTML bundle commands Preview in Running Browsers and Refresh Running Browsers. Preview is quite trivial, the core of the script is simple:

tell application "Opera"
  activate
  OpenURL "http://www.example.com/"
end tell

Using already predefined methods, we will adjust the script so it can be added to other browser directives in the bundle. First we're checking if the application is open, then passing on the AppleScript using the shell command osascript, replacing the URL with $activeURL variable. (Note, that it should be entered as a single line, it's split for better readability.)

[[ $(ps -xc|grep Opera) ]] && osascript ¬
-e 'tell application "Opera"' ¬
-e 'activate' ¬
-e "OpenURL \"$activeURL\"" ¬
-e 'end tell'

Just add to the Preview in Running Browsers HTML bundle command and next time you hit ⌃+⌘+P, Opera will preview your document (if opened).

Complementary to preview, let's add Opera to Refresh Running Browsers command too. Since we have no refresh function available, we will have to resort to a workaround. Assuming the opened document is in the frontmost window, we could just get the existing URL and apply it right back.

tell application "Opera"
  activate
  set link to get URL of front window
  set URL of front window to link
end tell

And in the form for TextMate bundle command:

ps -xc|grep -sqi Opera && osascript ¬
-e 'tell application "Opera"' ¬
-e 'activate' ¬
-e 'set link to get URL of front window' ¬
-e 'set URL of front window to link' ¬
-e 'end tell'

Add as a single line to the Refresh Running Browsers command and exit the Bundle Editor to save the changes. Next time you want to preview current TextMate document (⌃+⌘+P) or to refresh the preview to see latest edits (⌘+R), Opera will happily jump in, along with your other opened browsers.

zizkov


nedele

borg

...from this universe
July 2008
MTWTFSS
June 2008August 2008
123456
78910111213
14151617181920
21222324252627
28293031