em Sem categoria

Script Perl para abrir uma janela do browser padrão no OS X

O script Perl abaixo têm como principal função abrir uma janela do Safari do OS X através do shell, uma das possibilidades é enviar um comando por exemplo de um Iphone para controlar o navegador da máquina desktop.

#!/usr/bin/perl -w
use strict;
sub runAppleScript($)
{
my ($ascript) = @_;

my $result = `/usr/bin/osascript<<" EOT" $ascript EOT `; chomp($result); return $result; }# newSafariWindowWithUrl: Opens a new Safari window with the given URL sub newSafariWindowWithUrl($) { my ($url) = @_;runAppleScript(qq(tell application "Safari" activate make new document at end of documents set URL of document 1 to "$url" end tell)); }# newSafariTabWithUrl: Opens a new Safari tab with the given URL sub newSafariTabWithUrl($) { my ($url) = @_;runAppleScript(qq(-- bring Safari to the front tell application "Safari" activate end-- check that GUI Scripting has been enabled tell application "System Events" if UI elements enabled is false then tell application "Safari" make new document at end of documents set URL of document 1 to "http://www.apple.com/applescript/uiscripting/01.html" end tell set message to "You need to enable Assistive Devices as explained on this web page" display dialog message buttons {"OK"} return end if end tell-- create the new tab tell application "System Events" tell process "Safari" click menu item "New Tab" of menu "File" of menu bar 1 end tell end tell-- set the new tab to show the given URL tell application "Safari" set URL of document 1 to "$url" end tell)); }# -- MAIN --my $topic = ""; if (@ARGV >= 1)
{
$topic = $ARGV[0];
}

# Uncomment whichever of the two functions you want to use:
#newSafariTabWithUrl(“man:$topic”);
newSafariWindowWithUrl(“man:$topic”);