001 | #! /usr/bin/env osascript |
002 | ----+----1----+----2----+-----3----+----4----+----5----+----6----+----7 |
003 | (* |
004 | クリップボードの中身で保存可能なものを |
005 | ダウンロードフォルダに保存します |
006 |
|
007 | v1初回作成 |
008 | v2 リンクファイルを追加 |
009 | v2.1 テキストの中身がURLならWEBLOC保存 |
010 | v.2.2 Microsoft Edgeのオプション保存を追加 |
011 | org.microsoft.link-preview |
012 | org.microsoft.titled-hyperlink |
013 | v2.3 選択範囲テキストのフラグメントURLに対応 |
014 | v2.4 ローケーションファイルの拡張子の分岐を作成 |
015 | v2.4.1 画像をコピー等でテキスト無い場合のエラーに対応 |
016 | v2.5 テキストクリッピングでの保存を追加 |
017 | v2.5.1 UTI-Dataのmissing value対策を入れた |
018 | v2.6 TIFFデータがある場合OCRを実行して結果を保存するようにした |
019 |
|
020 | com.cocolog-nifty.quicktimer.icefloe *) |
021 | ----+----1----+----2----+-----3----+----4----+----5----+----6----+----7 |
022 | use AppleScript version "2.8" |
023 | use framework "Foundation" |
024 | use framework "AppKit" |
025 | use framework "UniformTypeIdentifiers" |
026 | use framework "VisionKit" |
027 | use framework "Vision" |
028 | use scripting additions |
029 |
|
030 | property refMe : a reference to current application |
031 |
|
032 | ################################ |
033 | ##### パス関連 |
034 | ################################ |
035 | ###フォルダ名用に時間を取得する |
036 | set strDateno to doGetDateNo("yyyyMMdd-hhmmss") as text |
037 | ###保存先 |
038 | set appFileManager to refMe's NSFileManager's defaultManager() |
039 | set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSDownloadsDirectory) inDomains:(refMe's NSUserDomainMask)) |
040 | set ocidDownloadsDirPathURL to ocidURLsArray's firstObject() |
041 | set strSubDirName to ("Pasteboard/" & strDateno) as text |
042 | set ocidSaveParentsDirPathURL to ocidDownloadsDirPathURL's URLByAppendingPathComponent:(strSubDirName) isDirectory:(true) |
043 | #フォルダ生成 |
044 | set ocidAttrDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0 |
045 | ocidAttrDict's setValue:(448) forKey:(refMe's NSFilePosixPermissions) |
046 | set listDone to appFileManager's createDirectoryAtURL:(ocidSaveParentsDirPathURL) withIntermediateDirectories:true attributes:(ocidAttrDict) |error|:(reference) |
047 | if (item 1 of listDone) is true then |
048 | log "正常処理" |
049 | else if (item 2 of listDone) ≠ (missing value) then |
050 | set strErrorNO to (item 2 of listDone)'s code() as text |
051 | set strErrorMes to (item 2 of listDone)'s localizedDescription() as text |
052 | refMe's NSLog("■:" & strErrorNO & strErrorMes) |
053 | return "エラーしました" & strErrorNO & strErrorMes |
054 | end if |
055 |
|
056 | ################################ |
057 | ######ペーストボードを取得 |
058 | ################################ |
059 | set ocidPasteboard to refMe's NSPasteboard's generalPasteboard() |
060 | #タイプを取得 |
061 | set ocidPastBoardTypeArray to ocidPasteboard's types() |
062 | log ocidPastBoardTypeArray as list |
063 |
|
064 | set strText to ("") |
065 | ######################### |
066 | #【1】FILEURL処理 |
067 | set boolContain to ocidPastBoardTypeArray's containsObject:("NSFilenamesPboardType") |
068 | if boolContain is true then |
069 | set ocidPastBoardData to (ocidPasteboard's propertyListForType:("NSFilenamesPboardType")) |
070 | #パス出力用 |
071 | set ocidFileNamesString to refMe's NSMutableString's alloc()'s init() |
072 | #順番に処理 |
073 | repeat with itemData in ocidPastBoardData |
074 | #出力用のテキストにそのまま追加して改行入れる |
075 | (ocidFileNamesString's appendString:(itemData)) |
076 | (ocidFileNamesString's appendString:("\n")) |
077 | #NSURLにして |
078 | set ocidItemFilePath to itemData's stringByStandardizingPath() |
079 | set ocidFilePathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidItemFilePath)) |
080 | #ファイル名から |
081 | set ocidFileName to ocidFilePathURL's lastPathComponent() |
082 | set ocidBaseFileName to ocidFileName's stringByDeletingPathExtension() |
083 | set ocidSaveFileName to (ocidBaseFileName's stringByAppendingPathExtension:("fileloc")) |
084 | #保存先のURLを作成 |
085 | set ocidPlistFilePathURL to (ocidSaveParentsDirPathURL's URLByAppendingPathComponent:(ocidSaveFileName) isDirectory:(false)) |
086 | set ocidItemFilePath to ocidFilePathURL's absoluteString() |
087 | #DICTにして |
088 | set ocidPlistDict to refMe's NSMutableDictionary's alloc()'s init() |
089 | (ocidPlistDict's setValue:(ocidItemFilePath) forKey:("URL")) |
090 | #PLISTに |
091 | set ocidFormat to (refMe's NSPropertyListXMLFormat_v1_0) |
092 | set listResponse to (refMe's NSPropertyListSerialization's dataWithPropertyList:(ocidPlistDict) format:(ocidFormat) options:0 |error|:(reference)) |
093 | set ocidPlistData to (item 1 of listResponse) |
094 | #保存 |
095 | set ocidOption to (refMe's NSDataWritingAtomic) |
096 | set listDone to (ocidPlistData's writeToURL:(ocidPlistFilePathURL) options:(ocidOption) |error|:(reference)) |
097 | |
098 | end repeat |
099 | set ocidSaveFilePathURL to (ocidSaveParentsDirPathURL's URLByAppendingPathComponent:("NSFilenamesPboardType.txt") isDirectory:(false)) |
100 | set listDone to ocidFileNamesString's writeToURL:(ocidSaveFilePathURL) atomically:(true) encoding:(refMe's NSUTF8StringEncoding) |error|:(reference) |
101 | end if |
102 |
|
103 | ######################### |
104 | #【2】org.chromium.source-url処理 |
105 | set boolContain to ocidPastBoardTypeArray's containsObject:("org.chromium.source-url") |
106 | if boolContain is true then |
107 | set ocidPastBoardData to (ocidPasteboard's dataForType:("org.chromium.source-url")) |
108 | set ocidURLstring to refMe's NSString's alloc()'s initWithData:(ocidPastBoardData) encoding:(refMe's NSUTF8StringEncoding) |
109 | #一度URLにして |
110 | set ocidURL to (refMe's NSURL's alloc()'s initWithString:(ocidURLstring)) |
111 | |
112 | #ファイル名用にHOST名を取得 |
113 | set strHostName to ocidURL's |host|() as text |
114 | #保存用拡張子を付与 |
115 | set ocidItemSaveFileName to ("" & strHostName & ".webloc") |
116 | #DICTにして |
117 | set ocidPlistDict to refMe's NSMutableDictionary's alloc()'s init() |
118 | (ocidPlistDict's setValue:(ocidURLstring) forKey:("URL")) |
119 | #PLISTに |
120 | set ocidFormat to (refMe's NSPropertyListXMLFormat_v1_0) |
121 | set listResponse to (refMe's NSPropertyListSerialization's dataWithPropertyList:(ocidPlistDict) format:(ocidFormat) options:0 |error|:(reference)) |
122 | set ocidPlistData to (item 1 of listResponse) |
123 | #保存先 |
124 | set ocidPlistFilePathURL to (ocidSaveParentsDirPathURL's URLByAppendingPathComponent:(ocidItemSaveFileName) isDirectory:(false)) |
125 | #保存 |
126 | set ocidOption to (refMe's NSDataWritingAtomic) |
127 | set listDone to (ocidPlistData's writeToURL:(ocidPlistFilePathURL) options:(ocidOption) |error|:(reference)) |
128 | ##テキストでも保存しておく |
129 | set ocidItemSaveFileName to ("org.chromium.source-url.txt") as text |
130 | set ocidSaveURLFilePathURL to (ocidSaveParentsDirPathURL's URLByAppendingPathComponent:(ocidItemSaveFileName) isDirectory:(false)) |
131 | # |
132 | set listDone to ocidURLstring's writeToURL:(ocidSaveURLFilePathURL) atomically:(true) encoding:(refMe's NSUTF8StringEncoding) |error|:(reference) |
133 | |
134 | end if |
135 | ######################### |
136 | #カレンダー |
137 | set boolContain to ocidPastBoardTypeArray's containsObject:("com.apple.calendar.pasteboard.event") |
138 | if boolContain is true then |
139 | set ocidPastBoardData to (ocidPasteboard's dataForType:("com.apple.calendar.pasteboard.event")) |
140 | set ocidEventIDstring to refMe's NSString's alloc()'s initWithData:(ocidPastBoardData) encoding:(refMe's NSUTF8StringEncoding) |
141 | log ocidEventIDstring as text |
142 | end if |
143 |
|
144 | set boolContain to ocidPastBoardTypeArray's containsObject:("com.apple.iCal.pasteboard.dragOriginDate") |
145 | if boolContain is true then |
146 | set ocidPastBoardData to (ocidPasteboard's dataForType:("com.apple.iCal.pasteboard.dragOriginDate")) |
147 | set ocidEventIDstring to refMe's NSString's alloc()'s initWithData:(ocidPastBoardData) encoding:(refMe's NSUTF8StringEncoding) |
148 | log ocidEventIDstring as text |
149 | end if |
150 |
|
151 | ######################### |
152 | #【3】public.url処理 |
153 | set boolContain to ocidPastBoardTypeArray's containsObject:("public.url") |
154 | if boolContain is true then |
155 | set ocidPastBoardData to (ocidPasteboard's dataForType:("public.url")) |
156 | set ocidURLstring to refMe's NSString's alloc()'s initWithData:(ocidPastBoardData) encoding:(refMe's NSUTF8StringEncoding) |
157 | set ocidURL to (refMe's NSURL's alloc()'s initWithString:(ocidURLstring)) |
158 | # |
159 | set ocidURLomponents to refMe's NSURLComponents's componentsWithURL:(ocidURL) resolvingAgainstBaseURL:(false) |
160 | set strScheme to ocidURLomponents's |scheme|() as text |
161 | if strScheme starts with "http" then |
162 | set strSaveExtension to ("webloc") as text |
163 | else if strScheme starts with "mail" then |
164 | set strSaveExtension to ("mailloc") as text |
165 | else if strScheme starts with "ftp" then |
166 | set strSaveExtension to ("ftploc") as text |
167 | else if strScheme starts with "atp" then |
168 | set strSaveExtension to ("afploc") as text |
169 | else if strScheme starts with "file" then |
170 | set strSaveExtension to ("fileloc") as text |
171 | else if strScheme starts with "news" then |
172 | set strSaveExtension to ("newsloc") as text |
173 | else |
174 | set strSaveExtension to ("inetloc") as text |
175 | end if |
176 | |
177 | set boolContain to ocidPastBoardTypeArray's containsObject:("public.url-name") |
178 | if boolContain is true then |
179 | set ocidPastBoardData to (ocidPasteboard's dataForType:("public.url-name")) |
180 | set ocidURLname to refMe's NSString's alloc()'s initWithData:(ocidPastBoardData) encoding:(refMe's NSUTF8StringEncoding) |
181 | set strSaveFileName to ("" & (ocidURLname as text) & "." & strSaveExtension & "") as text |
182 | else if boolContain is false then |
183 | set ocidHostName to ocidURL's |host|() |
184 | set strSaveFileName to ("" & (ocidHostName as text) & "." & strSaveExtension & "") as text |
185 | end if |
186 | #DICTにして |
187 | set ocidPlistDict to refMe's NSMutableDictionary's alloc()'s init() |
188 | (ocidPlistDict's setValue:(ocidURLstring) forKey:("URL")) |
189 | #PLISTに |
190 | set ocidFormat to (refMe's NSPropertyListXMLFormat_v1_0) |
191 | set listResponse to (refMe's NSPropertyListSerialization's dataWithPropertyList:(ocidPlistDict) format:(ocidFormat) options:0 |error|:(reference)) |
192 | set ocidPlistData to (item 1 of listResponse) |
193 | #保存先 |
194 | set ocidPlistFilePathURL to (ocidSaveParentsDirPathURL's URLByAppendingPathComponent:(strSaveFileName) isDirectory:(false)) |
195 | #保存 |
196 | set ocidOption to (refMe's NSDataWritingAtomic) |
197 | set listDone to (ocidPlistData's writeToURL:(ocidPlistFilePathURL) options:(ocidOption) |error|:(reference)) |
198 | end if |
199 |
|
200 | ######################### |
201 | #textClipping |
202 | set ocidTextClippingDict to refMe's NSMutableDictionary's alloc()'s init() |
203 | set ocidUTIDataDict to refMe's NSMutableDictionary's alloc()'s init() |
204 | #全タイプ処理する |
205 | repeat with itemPasteType in ocidPastBoardTypeArray |
206 | if (itemPasteType as text) is "public.utf8-plain-text" then |
207 | set ocidPastBoardData to (ocidPasteboard's dataForType:(itemPasteType)) |
208 | (ocidUTIDataDict's setValue:(ocidPastBoardData) forKey:(itemPasteType)) |
209 | else if (itemPasteType as text) is "public.utf16-external-plain-text" then |
210 | set ocidPastBoardData to (ocidPasteboard's dataForType:(itemPasteType)) |
211 | (ocidUTIDataDict's setValue:(ocidPastBoardData) forKey:(itemPasteType)) |
212 | else if (itemPasteType as text) is "public.utf16-plain-text" then |
213 | set ocidPastBoardData to (ocidPasteboard's dataForType:(itemPasteType)) |
214 | (ocidUTIDataDict's setValue:(ocidPastBoardData) forKey:(itemPasteType)) |
215 | else if (itemPasteType as text) is "com.apple.traditional-mac-plain-text" then |
216 | set ocidPastBoardData to (ocidPasteboard's dataForType:(itemPasteType)) |
217 | (ocidUTIDataDict's setValue:(ocidPastBoardData) forKey:(itemPasteType)) |
218 | else if (itemPasteType as text) is "public.rtf" then |
219 | set ocidPastBoardData to (ocidPasteboard's dataForType:(itemPasteType)) |
220 | set ocidRTFString to (refMe's NSString's alloc()'s initWithData:(ocidPastBoardData) encoding:(refMe's NSUTF8StringEncoding)) |
221 | (ocidUTIDataDict's setValue:(ocidRTFString) forKey:(itemPasteType)) |
222 | else |
223 | set ocidUTIDataDict to (missing value) |
224 | end if |
225 | end repeat |
226 | if ocidUTIDataDict ≠ (missing value) then |
227 | ocidTextClippingDict's setObject:(ocidUTIDataDict) forKey:("UTI-Data") |
228 | #PLISTデータに |
229 | set ocidFormat to (refMe's NSPropertyListBinaryFormat_v1_0) |
230 | set listResponse to refMe's NSPropertyListSerialization's dataWithPropertyList:(ocidTextClippingDict) format:(ocidFormat) options:0 |error|:(reference) |
231 | set ocidPlistData to (first item of listResponse) |
232 | #保存先パス |
233 | set strSaveFileName to ("UTI-Data.textClipping") as text |
234 | set ocidSaveFilePath to ocidSaveParentsDirPathURL's URLByAppendingPathComponent:(strSaveFileName) isDirectory:(false) |
235 | #保存 |
236 | set ocidOption to (refMe's NSDataWritingAtomic) |
237 | set listDone to (ocidPlistData's writeToURL:(ocidSaveFilePath) options:(ocidOption) |error|:(reference)) |
238 | end if |
239 |
|
240 |
|
241 | ######################### |
242 | #全タイプ処理する |
243 | repeat with itemPasteType in ocidPastBoardTypeArray |
244 | #【1】全タイプ処理 拡張子を決めておく |
245 | if (itemPasteType as text) is "public.utf8-plain-text" then |
246 | set strExtension to ("utf8.txt") as text |
247 | else if (itemPasteType as text) is "public.utf16-external-plain-text" then |
248 | set strExtension to ("utf16.txt") as text |
249 | else |
250 | #UTTypeを取得 |
251 | set ocidUTType to (refMe's UTType's typeWithIdentifier:(itemPasteType)) |
252 | #取得できない |
253 | if ocidUTType = (missing value) then |
254 | set strExtension to (missing value) |
255 | else if ocidUTType ≠ (missing value) then |
256 | set ocidExtension to (ocidUTType's preferredFilenameExtension()) |
257 | if ocidExtension = (missing value) then |
258 | set strExtension to (missing value) |
259 | else |
260 | set strExtension to (ocidExtension) as text |
261 | end if |
262 | end if |
263 | end if |
264 | #【2】データを取得 |
265 | if strExtension = (missing value) then |
266 | #拡張子がわからなかったモノは処理しない |
267 | else |
268 | log strExtension |
269 | #データ取り出し |
270 | set ocidPastBoardData to (ocidPasteboard's dataForType:(itemPasteType)) |
271 | if strExtension is "utf8.txt" then |
272 | set ocidTypeClassArray to (refMe's NSMutableArray's alloc()'s init()) |
273 | (ocidTypeClassArray's addObject:(refMe's NSString)) |
274 | set ocidReadString to (ocidPasteboard's readObjectsForClasses:(ocidTypeClassArray) options:(missing value)) |
275 | set strText to ocidReadString as text |
276 | else if strExtension is "tiff" then |
277 | #TIFFを元にOCRする |
278 | set ocidReadImage to (refMe's NSImage's alloc()'s initWithData:(ocidPastBoardData)) |
279 | set ocidImageRepArray to ocidReadImage's representations() |
280 | set ocidImageRep to ocidImageRepArray's firstObject() |
281 | set ocidPxSizeH to ocidImageRep's pixelsHigh() |
282 | #とっとと解放 |
283 | set ocidImageRepArray to "" |
284 | set ocidImageRep to "" |
285 | set intTextHeight to (8 / ocidPxSizeH) as number |
286 | #####OCR |
287 | #VNImageRequestHandler's |
288 | set ocidHandler to (refMe's VNImageRequestHandler's alloc()'s initWithData:(ocidPastBoardData) options:(missing value)) |
289 | #VNRecognizeTextRequest's |
290 | set ocidRequest to refMe's VNRecognizeTextRequest's alloc()'s init() |
291 | set ocidOption to (refMe's VNRequestTextRecognitionLevelAccurate) |
292 | (ocidRequest's setRecognitionLevel:(ocidOption)) |
293 | (ocidRequest's setMinimumTextHeight:(intTextHeight)) |
294 | (ocidRequest's setAutomaticallyDetectsLanguage:(true)) |
295 | (ocidRequest's setRecognitionLanguages:{"en", "ja"}) |
296 | (ocidRequest's setUsesLanguageCorrection:(false)) |
297 | #results |
298 | (ocidHandler's performRequests:(refMe's NSArray's arrayWithObject:(ocidRequest)) |error|:(reference)) |
299 | set ocidResponseArray to ocidRequest's results() |
300 | #戻り値を格納するテキスト |
301 | set ocidFirstOpinionString to (refMe's NSMutableString's alloc()'s initWithCapacity:(0)) |
302 | set ocidSecondOpinionString to (refMe's NSMutableString's alloc()'s initWithCapacity:(0)) |
303 | set ocidSaveString to (refMe's NSMutableString's alloc()'s initWithCapacity:(0)) |
304 | #戻り値の数だけ々 |
305 | repeat with itemArray in ocidResponseArray |
306 | #候補数指定 1−10 ここでは2種の候補を戻す指定 |
307 | set ocidRecognizedTextArray to (itemArray's topCandidates:(2)) |
308 | set ocidFirstOpinion to ocidRecognizedTextArray's firstObject() |
309 | set ocidSecondOpinion to ocidRecognizedTextArray's lastObject() |
310 | (ocidFirstOpinionString's appendString:(ocidFirstOpinion's |string|())) |
311 | (ocidFirstOpinionString's appendString:("\n")) |
312 | (ocidSecondOpinionString's appendString:(ocidSecondOpinion's |string|())) |
313 | (ocidSecondOpinionString's appendString:("\n")) |
314 | end repeat |
315 | ##比較して相違点を探すならここで |
316 | (ocidSaveString's appendString:("-----第1候補\n\n")) |
317 | (ocidSaveString's appendString:(ocidFirstOpinionString)) |
318 | (ocidSaveString's appendString:("\n\n-----第2候補\n\n")) |
319 | (ocidSaveString's appendString:(ocidSecondOpinionString)) |
320 | ###保存 |
321 | set ocidBaseFilePathURL to (ocidSaveParentsDirPathURL's URLByAppendingPathComponent:(itemPasteType) isDirectory:(false)) |
322 | set ocidSaveTextFilePathURL to (ocidBaseFilePathURL's URLByAppendingPathExtension:("OCR.txt")) |
323 | |
324 | set listDone to (ocidSaveString's writeToURL:(ocidSaveTextFilePathURL) atomically:(true) encoding:(refMe's NSUTF8StringEncoding) |error|:(reference)) |
325 | end if |
326 | #保存先パス |
327 | #ファイル名はUTI |
328 | set ocidBaseFilePathURL to (ocidSaveParentsDirPathURL's URLByAppendingPathComponent:(itemPasteType) isDirectory:(false)) |
329 | #拡張子つけて |
330 | set ocidSaveFilePathURL to (ocidBaseFilePathURL's URLByAppendingPathExtension:(strExtension)) |
331 | #保存 |
332 | set ocidOption to (refMe's NSDataWritingAtomic) |
333 | set listDone to (ocidPastBoardData's writeToURL:(ocidSaveFilePathURL) options:(ocidOption) |error|:(reference)) |
334 | if (item 1 of listDone) is true then |
335 | log "正常処理" |
336 | else if (item 2 of listDone) ≠ (missing value) then |
337 | set strErrorNO to (item 2 of listDone)'s code() as text |
338 | set strErrorMes to (item 2 of listDone)'s localizedDescription() as text |
339 | refMe's NSLog("■:" & strErrorNO & strErrorMes) |
340 | return "エラーしました" & strErrorNO & strErrorMes |
341 | end if |
342 | end if |
343 | end repeat |
344 |
|
345 |
|
346 |
|
347 | ################################ |
348 | #テキストがURLならWEBLOC保存を試す |
349 | ################################ |
350 | set ocidURLstring to refMe's NSString's stringWithString:(strText) |
351 | set ocidURLstring to (ocidURLstring's stringByReplacingOccurrencesOfString:("\r") withString:("\n")) |
352 | set ocidURLstring to (ocidURLstring's stringByReplacingOccurrencesOfString:("\n\n") withString:("\n")) |
353 | set ocidLineArray to ocidURLstring's componentsSeparatedByString:("\n") |
354 | repeat with itemLine in ocidLineArray |
355 | set ocidLineString to (itemLine's stringByReplacingOccurrencesOfString:("\t") withString:("")) |
356 | set boolHas to (ocidLineString's hasPrefix:("http")) as boolean |
357 | if boolHas is true then |
358 | set ocidURL to (refMe's NSURL's alloc()'s initWithString:(ocidURLstring)) |
359 | set ocidHOST to ocidURL's |host|() |
360 | set strSaveFileName to ("" & (ocidHOST as text) & ".make.webloc") as text |
361 | set ocidSaveFilePathURL to (ocidSaveParentsDirPathURL's URLByAppendingPathComponent:(strSaveFileName) isDirectory:(false)) |
362 | set ocidURLstring to ocidURL's absoluteString() |
363 | # |
364 | set ocidPlistDict to refMe's NSMutableDictionary's alloc()'s init() |
365 | (ocidPlistDict's setValue:(ocidURLstring) forKey:("URL")) |
366 | #PLIST2NSDATA(MutableContainersAndLeaves) |
367 | set ocidFromat to (refMe's NSPropertyListXMLFormat_v1_0) |
368 | set ocidFromat to (refMe's NSPropertyListBinaryFormat_v1_0) |
369 | set listResponse to (refMe's NSPropertyListSerialization's dataWithPropertyList:(ocidPlistDict) format:(ocidFromat) options:0 |error|:(reference)) |
370 | set ocidPlistData to (item 1 of listResponse) |
371 | #NSDATA |
372 | set ocidOption to (refMe's NSDataWritingAtomic) |
373 | set listDone to (ocidPlistData's writeToURL:(ocidSaveFilePathURL) options:(ocidOption) |error|:(reference)) |
374 | end if |
375 | end repeat |
376 |
|
377 | ################################ |
378 | ##### Microsoft Edgeカスタム |
379 | ################################ |
380 | set ocidPastBoardData to (ocidPasteboard's dataForType:("org.microsoft.link-preview")) |
381 | if ocidPastBoardData ≠ (missing value) then |
382 | set ocidJsonString to refMe's NSString's alloc()'s initWithData:(ocidPastBoardData) encoding:(refMe's NSUTF8StringEncoding) |
383 | set strSaveFileName to ("org.microsoft.link-preview.json") as text |
384 | set ocidSaveFilePathURL to (ocidSaveParentsDirPathURL's URLByAppendingPathComponent:(strSaveFileName) isDirectory:(false)) |
385 | set listDone to ocidJsonString's writeToURL:(ocidSaveFilePathURL) atomically:(true) encoding:(refMe's NSUTF8StringEncoding) |error|:(reference) |
386 | end if |
387 | ################################ |
388 | ##### Microsoft Edgeカスタム |
389 | ################################ |
390 | set ocidPastBoardString to (ocidPasteboard's stringForType:("org.microsoft.titled-hyperlink")) |
391 | if ocidPastBoardString ≠ (missing value) then |
392 | set ocidPastBoardString to (ocidPastBoardString's stringByReplacingOccurrencesOfString:("<meta charset='utf-8'>") withString:("")) |
393 | set strSaveFileName to ("org.microsoft.link-preview.html") as text |
394 | set ocidSaveFilePathURL to (ocidSaveParentsDirPathURL's URLByAppendingPathComponent:(strSaveFileName) isDirectory:(false)) |
395 | set listDone to ocidPastBoardString's writeToURL:(ocidSaveFilePathURL) atomically:(true) encoding:(refMe's NSUTF8StringEncoding) |error|:(reference) |
396 | end if |
397 | ################################ |
398 | ##### 保存先を開く |
399 | ################################ |
400 | set appSharedWorkspace to refMe's NSWorkspace's sharedWorkspace() |
401 | set boolDone to appSharedWorkspace's openURL:(ocidSaveParentsDirPathURL) |
402 |
|
403 | ################################ |
404 | ##### ファイル名用の時間 |
405 | ################################ |
406 | to doGetDateNo(strDateFormat) |
407 | ####日付情報の取得 |
408 | set ocidDate to current application's NSDate's |date|() |
409 | ###日付のフォーマットを定義 |
410 | set ocidNSDateFormatter to current application's NSDateFormatter's alloc()'s init() |
411 | ocidNSDateFormatter's setLocale:(current application's NSLocale's localeWithLocaleIdentifier:"ja_JP_POSIX") |
412 | ocidNSDateFormatter's setDateFormat:strDateFormat |
413 | set ocidDateAndTime to ocidNSDateFormatter's stringFromDate:ocidDate |
414 | set strDateAndTime to ocidDateAndTime as text |
415 | return strDateAndTime |
416 | end doGetDateNo |