2010-07-23 90 views
0

我需要根據讀取結果打開多個Safari(或打開標籤即可)。如何讀取文件並用Mac(AppleScript)的讀取結果打開Safari?

例如,如果一個文件有

 
http://a.com 
http://b.com 

我想用Safari瀏覽器打開a.com和b.com。

我該怎麼用Mac/AppleScript做到這一點?

也許我可以運行python調用「打開-a野生動物園」 http://a.com」,但我想AppleScript的是這種工作的工具。

+0

那個python解決方案(這真的只是一個通用控制檯解決方案)有什麼問題? – 2010-07-23 02:27:08

回答

3

不知道蟒蛇,但這將讀取文本文件和打開的窗口讓我看看我是否可以爲你設置標籤,雖然 設置地點的段落(閱讀(選擇文件時提示「選擇包含網址的文本文件」)) 在位置 重複與aline如果長度大於0,則 告訴應用程序「Safari」 在文檔末尾創建新文檔 將文檔1的URL設置爲aline e ND告訴 如果最終 端重複

編輯:

確定這是更好,它會打開他們在一個窗口的標籤

set locations to paragraphs of (read (choose file with prompt "Pick text file containing urls")) 
    tell application "Safari" 
    activate 
    set adoc to make new document 
    end tell 
    repeat with aline in locations 
    if length of aline is greater than 0 then 
     tell application "Safari" to make new tab at end of window 1 with properties {URL:aline} 
    end if 
    end repeat 

新Addtion

這是另一種基於regulus6633的帖子與我的結合的方式

set locations to paragraphs of (read (choose file with prompt "Pick text file containing urls")) 
repeat with aLocation in locations 
    tell application "Safari" to open location aLocation 
end repeat 
+0

謝謝,它像一個魅力。 – prosseek 2010-07-24 01:33:27

2

如果您希望它在Safari中專門打開鏈接,那麼mcgrailm的解決方案很好。但是,您不需要第一部分的Finder,因此需要將代碼從Finder tell塊中取出。沒有必要告訴Finder去做一些applescript可以做的事情。

但是,您可能希望在用戶的默認瀏覽器的任何瀏覽器中打開鏈接。它可能是Safari或Firefox等。你可以用「打開位置」命令來做到這一點。所以像這樣的東西可能是你想要的...

set theFile to choose file with prompt "Pick text file containing urls" 
set locations to paragraphs of (read theFile) 

repeat with aLocation in locations 
    try 
     open location aLocation 
    end try 
end repeat 
+0

好點我不需要發現者...好的工作我喜歡它 – mcgrailm 2010-07-23 17:09:41