还记得IE吗?

回到过去,Mac OS X的领先浏览器是Internet Explorer没错,孩子们 - 微软曾经写过Macintosh软件。

除了提供比那个时代任何其他浏览器更好的Web标准支持,IE for Mac也非常易于编写脚本事实上,你可以对我们进行微调保存和还原Safari URL今天早些时候发布的脚本,并与IE一起使用。

And, remarkably, aftering making these changes, the same scripts could be used both on Mac OS X and on the now-long-forgotten Mac OS 9 (a relic so old that it used the rainbow-colored Apple logo; ask your grandpa about it).

最大的变化是我们如何获得当前打开的URL列表而在Safari中我们只是说:

tell application "Safari"
    set url_list to URL of every document
end tell

IE强制我们手动创建这个列表,解析非对象模型脚本动词的结果这是怎么回事亚伯拉罕·林肯写脚本:

set url_list to {}
tell application "Internet Explorer"
    set win_list to ListWindows
    repeat with w in win_list
        set the_info to GetWindowInfo (w)
        copy item 1 of the_info to end of url_list
    end repeat
end tell

不用多说,脚本:

保存IE URL

set url_list to {}

tell application "Internet Explorer"
    set win_list to ListWindows
    repeat with w in win_list
        set the_info to GetWindowInfo (w)
        copy item 1 of the_info to end of url_list
    end repeat
end tell

-- convert url_list to text
set old_delim to AppleScript's text item delimiters
set AppleScript's text item delimiters to return
set url_list to url_list as text
set AppleScript's text item delimiters to old_delim

-- get path to prefs file where URLs will be stored
set prefs_folder to path to preferences folder as string
set prefs_file to prefs_folder & "Internet Explorer Saved URLs"

try
    set open_file to ¬
        open for access file prefs_file with write permission
    -- erase current contents of file:
    set eof of open_file to 0
    write url_list to open_file starting at eof
    close access open_file
on error
    try
        close access file prefs_file
    end try
end try

恢复IE URL

-- get path to prefs file where URLs are stored
set prefs_folder to path to preferences folder as string
set prefs_file to prefs_folder & "Internet Explorer Saved URLs"

try
    set open_file to ¬
        open for access file prefs_file without write permission
    set url_list to read open_file using delimiter return
    close access open_file
    tell application "Internet Explorer"
        repeat with the_url in url_list
            GetURL the_url
        end repeat
    end tell
on error
    try
        close access file prefs_file
    end try
end try

进一步阅读

杰西尚克斯

结合Safari,AppleScript和OS X系统的特性,可以创建一种新的更有效的浏览方式,使标签式浏览的问题变得无关紧要。

以前: 保存和还原Safari URL
下一个: Enkode这个