2012-07-29 30 views

Respuesta

7

La manera de crear una nueva ventana de Safari es utilizar el comando make new document:

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

Esto creará una nueva ventana con una sola pestaña que apunta a the_url y hacer que la ventana del primer plano. Tenga en cuenta que make new window at end of windows no funciona, y solo errores con "AppleEvent manejador falla".

Del mismo modo, para crear una nueva pestaña dentro de una ventana w, puede utilizar make new tab:

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

Esto creará una nueva pestaña en la ventana w al final de la lista de pestañas; esta pestaña apuntará a the_url, y no será la pestaña actual. En lugar de decir explícitamente tabs of w, también se puede utilizar un bloque tell w:

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

De esa manera, tabs se refiere implícitamente a tabs of w.

Poniendo todo esto junto, obtenemos el siguiente script. Dada una lista de URL en the_urls, las abrirá todas en una nueva ventana; si the_urls está vacío, abre una ventana con una pestaña en blanco.

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

gracias por la explicación adicional, Antal. ¡Funciona! – 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 

Reemplazar las X con lo sitios que desee y seguir repitiendo el código (mi new_tab() y establecer la dirección URL ... líneas) para cada página que le gustaría tener abierta. Refiriéndonos a this page. Corrígeme si esto no es de lo que estabas hablando.

+0

Gracias por la respuesta, Pugmatt. Está cerca de lo que quiero. Su secuencia de comandos abre la url en una ventana existente de Safari; deseo abrirla en una nueva ventana. – sevens

0

Base en la respuesta de Pugmatt me dio la siguiente para trabajar ...

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 

No estoy seguro de si este es el modo más eficiente de esto.

Cuestiones relacionadas