[firefox]WEBページのダウンロード保存(簡易版)
AppleScript サンプルコード
行番号 | ソース |
---|---|
001 | #!/usr/bin/env osascript |
002 | ----+----1----+----2----+-----3----+----4----+----5----+----6----+----7 |
003 | # |
004 | # |
005 | #com.cocolog-nifty.quicktimer.icefloe |
006 | ----+----1----+----2----+-----3----+----4----+----5----+----6----+----7 |
007 | use AppleScript version "2.8" |
008 | use framework "Foundation" |
009 | use framework "UniformTypeIdentifiers" |
010 | use framework "AppKit" |
011 | use scripting additions |
012 | property refMe : a reference to current application |
013 | |
014 | set aliasSharedDirPath to (path to shared documents from user domain) as alias |
015 | set strSharedDirPath to (POSIX path of aliasSharedDirPath) as text |
016 | set ocidSharedDirPathStr to refMe's NSString's stringWithString:(strSharedDirPath) |
017 | set ocidSharedDirPath to ocidSharedDirPathStr's stringByStandardizingPath() |
018 | set ocidSharedDirPathURL to refMe's NSURL's alloc()'s initFileURLWithPath:(ocidSharedDirPath) isDirectory:(false) |
019 | set ocidSharedDownloadsDirPathURL to ocidSharedDirPathURL's URLByAppendingPathComponent:("Downloads") isDirectory:(true) |
020 | # |
021 | set appFileManager to refMe's NSFileManager's defaultManager() |
022 | set ocidAttrDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0 |
023 | ocidAttrDict's setValue:(511) forKey:(refMe's NSFilePosixPermissions) |
024 | set listDone to appFileManager's createDirectoryAtURL:(ocidSharedDownloadsDirPathURL) withIntermediateDirectories:true attributes:(ocidAttrDict) |error| :(reference) |
025 | set aliasSharedDownloadsDirPath to (ocidSharedDownloadsDirPathURL's absoluteURL()) as alias |
026 | |
027 | set listURL to {"https://news.yahoo.co.jp/", "https://news.yahoo.co.jp/flash", "https://news.yahoo.co.jp/categories/world", "https://news.yahoo.co.jp/categories/domestic", "https://news.yahoo.co.jp/categories/business", "https://news.yahoo.co.jp/categories/entertainment", "https://news.yahoo.co.jp/categories/sports", "https://news.yahoo.co.jp/categories/it", "https://news.yahoo.co.jp/categories/life"} |
028 | |
029 | repeat with itemURL in listURL |
030 | |
031 | tell application id "org.mozilla.firefox" |
032 | close every window |
033 | end tell |
034 | delay 1 |
035 | |
036 | tell application id "org.mozilla.firefox" |
037 | open location itemURL |
038 | end tell |
039 | delay 5 |
040 | |
041 | |
042 | ###全面のタブのURLを取得して |
043 | ####ページ情報を開く |
044 | tell application "Firefox" |
045 | tell front window |
046 | activate |
047 | tell application "System Events" |
048 | tell process "Firefox" |
049 | keystroke "i" using {command down} |
050 | end tell |
051 | end tell |
052 | end tell |
053 | end tell |
054 | |
055 | delay 1 |
056 | |
057 | #####ページ情報の名称を取得 |
058 | tell application "Firefox" |
059 | tell window 1 |
060 | set strPageName to name as text |
061 | end tell |
062 | end tell |
063 | |
064 | ####ページ情報を閉じる |
065 | tell application "Firefox" |
066 | tell window 1 |
067 | close |
068 | end tell |
069 | end tell |
070 | |
071 | set strViewURL to doReplace(strPageName, "ページ情報 — ", "") |
072 | |
073 | |
074 | try |
075 | set strText to strViewURL as text |
076 | ####ペーストボード宣言 |
077 | set appPasteboard to refMe's NSPasteboard's generalPasteboard() |
078 | set ocidText to (refMe's NSString's stringWithString:(strText)) |
079 | appPasteboard's clearContents() |
080 | (appPasteboard's setString:(ocidText) forType:(refMe's NSPasteboardTypeString)) |
081 | on error |
082 | tell application "Finder" |
083 | set the clipboard to strText as text |
084 | end tell |
085 | end try |
086 | |
087 | ###全面のタブのURLを取得して |
088 | ####ページ情報を開く |
089 | tell application "Firefox" |
090 | tell front window |
091 | activate |
092 | tell application "System Events" |
093 | tell process "Firefox" |
094 | keystroke "j" using {command down} |
095 | end tell |
096 | end tell |
097 | end tell |
098 | end tell |
099 | |
100 | delay 1 |
101 | |
102 | ###全面のタブのURLを取得して |
103 | ####ページ情報を開く |
104 | tell application "Firefox" |
105 | tell front window |
106 | activate |
107 | tell application "System Events" |
108 | tell process "Firefox" |
109 | keystroke "v" using {command down} |
110 | end tell |
111 | end tell |
112 | end tell |
113 | end tell |
114 | |
115 | delay 1 |
116 | |
117 | tell application id "org.mozilla.firefox" |
118 | close every window |
119 | end tell |
120 | |
121 | end repeat |
122 | |
123 | |
124 | #################################### |
125 | ###### 文字の置換 |
126 | #################################### |
127 | to doReplace(theText, orgStr, newStr) |
128 | set oldDelim to AppleScript's text item delimiters |
129 | set AppleScript's text item delimiters to orgStr |
130 | set tmpList to every text item of theText |
131 | set AppleScript's text item delimiters to newStr |
132 | set tmpStr to tmpList as text |
133 | set AppleScript's text item delimiters to oldDelim |
134 | return tmpStr |
135 | end doReplace |
AppleScriptで生成しました |
| 固定リンク