2012-07-29 14 views
5

सफारी में एक नई विंडो कैसे खोलें और फिर सेब स्क्रिप्ट का उपयोग करके उस विंडो में विभिन्न यूआरएल के साथ कई टैब खोलें?सफारी में सेब स्क्रिप्ट के साथ एक नई विंडो और एकाधिक यूआरएल कैसे खोलें?

उत्तर

7

सफारी में एक नई विंडो बनाने के लिए जिस तरह से make new document आदेश का उपयोग करने के लिए है। ध्यान दें कि make new window at end of windows काम नहीं करता है, और "AppleEvent हैंडलर विफल रहता है" के साथ केवल त्रुटियां।

इसी तरह, एक खिड़की w भीतर एक नया टैब बनाने के लिए, आप make new tab उपयोग कर सकते हैं:

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

इस टैब की सूची के अंत में खिड़की w में एक नया टैब पैदा करेगा; यह टैब the_url पर इंगित करेगा, और यह वर्तमान टैब नहीं होगा।

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

इस तरह, tabs परोक्ष tabs of w को दर्शाता है: इसके बजाय स्पष्ट रूप से tabs of w कहने का, तो आप भी एक tell w ब्लॉक का उपयोग कर सकते हैं।

यह सब एक साथ रखकर, हमें निम्न स्क्रिप्ट मिलती है। the_urls में यूआरएल की एक सूची को देखते हुए, यह उन सभी को एक नई विंडो में खुल जाएगा; अगर the_urls खाली है, तो यह एक खाली टैब के साथ एक विंडो खुलता है।

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

धन्यवाद। यह काम करता हैं! – 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 

जो कुछ साइटों आप चाहते हैं के साथ एक्स के बदलें और कोड दोहरा रखने के (मेरे new_tab() और URL ... लाइनों सेट) प्रत्येक पृष्ठ आपके द्वारा खोली गई करना चाहते हैं के लिए। this page. का जिक्र करते हुए मुझे सही करें अगर यह नहीं है कि आप किस बारे में बात कर रहे थे। Pugmatt के जवाब पर

+0

प्रतिक्रिया के लिए धन्यवाद, पगमैट। यह मेरी इच्छा के करीब है। आपकी स्क्रिप्ट एक मौजूदा सफारी विंडो में यूआरएल खोलती है - मैं फिर एक नई विंडो में खोलना चाहता हूं। अतिरिक्त स्पष्टीकरण, एंटल के लिए – sevens

0

बेस मैं काम करने के लिए निम्नलिखित मिल गया ...

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 

मुझे यकीन है कि अगर यह आप इस के लिए सबसे कारगर तरीका है नहीं कर रहा हूँ।

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

यह एक एकल टैब the_url की ओर इशारा करते के साथ एक नई विंडो बनाने और उस खिड़की frontmost कर देगा:

संबंधित मुद्दे