2012-07-29 11 views

Antwort

7

Die Art und Weise ein neues Fenster in Safari zu erstellen, ist den make new document Befehl zu verwenden:

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

Dadurch wird ein neues Fenster mit einem einzigen Tab erstellen, um the_url zeigen und das Fenster vorderste machen. Beachten Sie, dass make new window at end of windows nicht funktioniert, und nur Fehler mit "AppleEvent-Handler schlägt fehl".

In ähnlicher Weise eine neue Registerkarte innerhalb eines Fensters erstellen w, können Sie make new tab verwenden:

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

Dies wird eine neue Registerkarte in Fenster w am Ende der Liste der Registerkarten erstellen; Diese Registerkarte wird auf the_url zeigen und wird nicht die aktuelle Registerkarte sein. Statt explizit tabs of w sagen, können Sie auch einen tell w Block verwenden:

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

Auf diese Weise tabs verweist implizit auf tabs of w.

Wir fügen das folgende Skript hinzu. Bei einer Liste von URLs in the_urls werden alle in einem neuen Fenster geöffnet. Wenn the_urls leer ist, wird ein Fenster mit einer leeren Registerkarte geöffnet.

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

danke für die zusätzliche Erklärung, Antal. Es klappt! – 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 

Ersetzen Sie die X mit dem, was Websites, die Sie wollen, und halten Sie den Code (meine NEW_TAB() und stellen Sie die URL ... Linien) Wiederholung für jede Seite, die Sie geöffnet haben möchten. Mit Bezug auf this page. Korrigieren Sie mich, wenn dies nicht das ist, worüber Sie gesprochen haben.

+0

Danke für die Antwort, Pugmatt. Es ist nah dran was ich will. Ihr Skript öffnet die URL in einem vorhandenen Safari-Fenster - ich möchte es dann in einem neuen Fenster öffnen. – sevens

0

Base auf Pugmatt Antwort bekam ich folgendes zu arbeiten ...

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 

Ich bin nicht sicher, ob dies der effizienteste Weg, Ihnen diese ist.

Verwandte Themen