2012-07-29 9 views

risposta

7

Il modo per creare una nuova finestra di Safari è quello di utilizzare il comando make new document:

make new document at end of documents with properties {URL:the_url} 

questo creerà una nuova finestra con una singola scheda che indica the_url e fare quella finestra in primo piano. Si noti che make new window at end of windows non funziona e si verificano solo errori con "Mancato funzionamento di AppleEvent".

Allo stesso modo, per creare una nuova scheda all'interno di una finestra w, è possibile utilizzare make new tab:

make new tab at end of tabs of w with properties {URL:the_url} 

questo creerà una nuova scheda nella finestra di w alla fine dell'elenco delle schede; questa scheda punterà a the_url, e non sarà essere la scheda corrente. Invece di dire esplicitamente tabs of w, è anche possibile utilizzare un blocco tell w:

tell w 
    make new tab at end of tabs with properties {URL:the_url} 
end tell 

In questo modo, tabs si riferisce implicitamente alla tabs of w.

Mettendo tutto questo insieme, otteniamo il seguente script. Dato un elenco di URL in the_urls, verrà aperto tutti in una nuova finestra; se the_urls è vuoto, apre una finestra con una scheda vuota.

property the_urls : {¬ 
    "http://stackoverflow.com", ¬ 
    "http://tex.stackexchange.com", ¬ 
    "http://apple.stackexchange.com"} 

tell application "Safari" 
    if the_urls = {} then 
     -- If you don't want to open a new window for an empty list, replace the 
     -- following line with just "return" 
     set {first_url, rest_urls} to {"", {}} 
    else 
     -- `item 1 of ...` gets the first item of a list, `rest of ...` gets 
     -- everything after the first item of a list. We treat the two 
     -- differently because the first item must be placed in a new window, but 
     -- everything else must be placed in a new tab. 
     set {first_url, rest_urls} to {item 1 of the_urls, rest of the_urls} 
    end if 

    make new document at end of documents with properties {URL:first_url} 
    tell window 1 
     repeat with the_url in rest_urls 
      make new tab at end of tabs with properties {URL:the_url} 
     end repeat 
    end tell 
end tell 
+0

grazie per la spiegazione aggiuntiva, Antal. Funziona! – sevens

1
tell application "Safari" 
    activate 
    set the URL of document 1 to "http://www.XXXXXXX.com" 
    my new_tab() 
    set the URL of document 1 to "http://www.XXXXXX.com" 
end tell 
on new_tab() 
    tell application "Safari" to activate 
    tell application "System Events" 
    tell process "Safari" 
     «event prcsclic» «class menI» "New Tab" of «class menE» "File" of «class mbar» 1 
    end tell 
    end tell 
end new_tab 

Sostituire le X con qualsiasi sito che si desidera e continuare a ripetere il codice (il mio new_tab() e impostare l'URL ... righe) per ogni pagina che si desidera avere aperto. Riferimento a this page. Correggimi se questo non è quello di cui stavi parlando.

+0

Grazie per la risposta, Pugmatt. È vicino a quello che voglio. Il tuo script apre l'url in una finestra di Safari esistente: voglio aprirlo in una nuova finestra. – sevens

0

Base sulla risposta di Pugmatt ho ottenuto il seguente al lavoro ...

on run {input, parameters} 
    tell application "Safari" 
    activate 
    make new document with properties {URL:"http://www.apple.com"} 
    my new_tab() 
    set the URL of document 1 to "http://www.example.com" 
    end tell 
end run 
on new_tab() 
    tell application "Safari" to activate 
    tell application "System Events" 
    tell process "Safari" 
     «event prcsclic» «class menI» "New Tab" of «class menE» "File" of «class mbar» 1 
    end tell 
    end tell 
end new_tab 

Non sono sicuro se questo è il modo più efficiente di questo.

Problemi correlati