001 | #!/usr/bin/env osascript |
---|
002 | ----+----1----+----2----+-----3----+----4----+----5----+----6----+----7 |
---|
003 | # |
---|
004 | # |
---|
005 | # |
---|
006 | # |
---|
007 | # com.cocolog-nifty.quicktimer.icefloe |
---|
008 | ----+----1----+----2----+-----3----+----4----+----5----+----6----+----7 |
---|
009 | ##自分環境がos12なので2.8にしているだけです |
---|
010 | use AppleScript version "2.8" |
---|
011 | use framework "Foundation" |
---|
012 | use framework "CoreImage" |
---|
013 | use scripting additions |
---|
014 | |
---|
015 | property objMe : a reference to current application |
---|
016 | property objNSString : a reference to objMe's NSString |
---|
017 | property objNSURL : a reference to objMe's NSURL |
---|
018 | ## |
---|
019 | property objNSDictionary : a reference to objMe's NSDictionary |
---|
020 | property objNSMutableDictionary : a reference to objMe's NSMutableDictionary |
---|
021 | property objNSArray : a reference to objMe's NSArray |
---|
022 | property objNSMutableArray : a reference to objMe's NSMutableArray |
---|
023 | |
---|
024 | set objFileManager to objMe's NSFileManager's defaultManager() |
---|
025 | |
---|
026 | ###リセット |
---|
027 | set theURL to "" as text |
---|
028 | set ocidNSInlineData to "" as text |
---|
029 | set ocidNSBitmapImagePadRep to "" as text |
---|
030 | |
---|
031 | tell application "Finder" |
---|
032 | set the clipboard to the theURL as string |
---|
033 | end tell |
---|
034 | |
---|
035 | objMe's NSLog("■:osascript:Start Script Geo2Qr4Map") |
---|
036 | |
---|
037 | ###コピーのサブへ |
---|
038 | doCopyMap() |
---|
039 | |
---|
040 | log "theURL:" & theURL |
---|
041 | objMe's NSLog("■:osascript:コピー OK" & theURL & "") |
---|
042 | ###クリップボードからURLを取得する |
---|
043 | tell application "Finder" |
---|
044 | set theURL to (the clipboard) as text |
---|
045 | end tell |
---|
046 | delay 0.5 |
---|
047 | |
---|
048 | ################################################## |
---|
049 | objMe's NSLog("■:osascript: theURL" & theURL & "") |
---|
050 | set strURL to theURL as text |
---|
051 | |
---|
052 | ################################################## |
---|
053 | if strURL is "" then |
---|
054 | ###URLの取得に失敗しているパターン |
---|
055 | set aliasIconPath to POSIX file "/System/Applications/Maps.app/Contents/Resources/AppIcon.icns" as alias |
---|
056 | set strDefaultAnswer to "https://maps.apple.com/?ll=35.658558,139.745504" as text |
---|
057 | try |
---|
058 | set objResponse to (display dialog "URLの取得に失敗しました" with title "QRテキスト" default answer strDefaultAnswer buttons {"OK", "キャンセル"} default button "OK" cancel button "キャンセル" with icon aliasIconPath giving up after 20 without hidden answer) |
---|
059 | on error |
---|
060 | log "エラーしました" |
---|
061 | return |
---|
062 | end try |
---|
063 | if true is equal to (gave up of objResponse) then |
---|
064 | return "時間切れですやりなおしてください" |
---|
065 | end if |
---|
066 | if "OK" is equal to (button returned of objResponse) then |
---|
067 | set strURL to (text returned of objResponse) as text |
---|
068 | else |
---|
069 | return "キャンセル" |
---|
070 | end if |
---|
071 | end if |
---|
072 | |
---|
073 | ############################ |
---|
074 | ##値がコピー出来なかったときエラーになるので |
---|
075 | ##ここはトライ |
---|
076 | try |
---|
077 | #################################### |
---|
078 | ###URLをNSURLに格納 |
---|
079 | set ocidURL to objNSURL's alloc's initWithString:strURL |
---|
080 | log className() of ocidURL as text |
---|
081 | --> NSURL |
---|
082 | #################################### |
---|
083 | ###クエリー部を取り出し |
---|
084 | set ocidQueryUrl to ocidURL's query |
---|
085 | log className() of ocidQueryUrl as text |
---|
086 | --> __NSCFString |
---|
087 | log ocidQueryUrl as text |
---|
088 | on error |
---|
089 | ###エラーしたらコピー取り直し |
---|
090 | doCopyMap() |
---|
091 | tell application "Finder" |
---|
092 | set theURL to (the clipboard) as text |
---|
093 | end tell |
---|
094 | #################################### |
---|
095 | ###URLをNSURLに格納 |
---|
096 | set ocidURL to objNSURL's alloc's initWithString:strURL |
---|
097 | log className() of ocidURL as text |
---|
098 | --> NSURL |
---|
099 | #################################### |
---|
100 | ###クエリー部を取り出し |
---|
101 | set ocidQueryUrl to ocidURL's query |
---|
102 | log className() of ocidQueryUrl as text |
---|
103 | --> __NSCFString |
---|
104 | log ocidQueryUrl as text |
---|
105 | end try |
---|
106 | |
---|
107 | #################################### |
---|
108 | ###取り出したクエリを&を区切り文字でリストに |
---|
109 | set ocidArrayComponent to (ocidQueryUrl's componentsSeparatedByString:"&") |
---|
110 | log className() of ocidArrayComponent as text |
---|
111 | --> __NSArrayM |
---|
112 | log ocidArrayComponent as list |
---|
113 | |
---|
114 | #################################### |
---|
115 | ####可変レコードを作成 |
---|
116 | set ocidRecordQuery to objNSMutableDictionary's alloc()'s init() |
---|
117 | ####値が空のレコードを定義 |
---|
118 | set recordQuery to {t:"", q:"", address:"", near:"", ll:"", z:"18", spn:"", saddr:"", daddr:"", dirflg:"", sll:"", sspn:"", ug:""} as record |
---|
119 | ####↑の定義で値が空の可変レコードを作成 |
---|
120 | set ocidRecordQuery to objNSMutableDictionary's dictionaryWithDictionary:recordQuery |
---|
121 | #################################### |
---|
122 | ###ここからクエリー分繰り返し |
---|
123 | repeat with objArrayComponent in ocidArrayComponent |
---|
124 | #####渡されたクエリーを=を境に分割してArray=リストにする |
---|
125 | set ocidArrayFirstObject to (objArrayComponent's componentsSeparatedByString:"=") |
---|
126 | |
---|
127 | ####まずは順番に キー と 値 で格納 |
---|
128 | set ocidKey to item 1 of ocidArrayFirstObject |
---|
129 | log ocidKey as text |
---|
130 | |
---|
131 | set ocidValue to item 2 of ocidArrayFirstObject |
---|
132 | log ocidValue as text |
---|
133 | |
---|
134 | #########位置情報 緯度 経度 |
---|
135 | if (ocidKey as text) = "ll" then |
---|
136 | set ll of ocidRecordQuery to ocidValue |
---|
137 | ####カンマでわけて緯度 経度に |
---|
138 | set ocidArrayLL to (ocidValue's componentsSeparatedByString:",") |
---|
139 | log ocidArrayLL as list |
---|
140 | ###最初の項目 |
---|
141 | set ocidLatitude to item 1 of ocidArrayLL |
---|
142 | log "Latitude:" & ocidLatitude as text |
---|
143 | ###あとの項目 |
---|
144 | set ocidLongitude to item 2 of ocidArrayLL |
---|
145 | log "Longitude:" & ocidLongitude as text |
---|
146 | |
---|
147 | #########Address String 住所 |
---|
148 | else if (ocidKey as text) = "address" then |
---|
149 | set address of ocidRecordQuery to ocidValue |
---|
150 | set ocidAddEnc to ocidValue's stringByRemovingPercentEncoding |
---|
151 | log "AddressString:" & ocidAddEnc as text |
---|
152 | |
---|
153 | #########The zoom level. 高さ方向 |
---|
154 | else if (ocidKey as text) = "z" then |
---|
155 | set z of ocidRecordQuery to ocidValue |
---|
156 | set ocidZoomValue to ocidValue |
---|
157 | log "ZoomValue:" & ocidZoomValue |
---|
158 | |
---|
159 | #########マップビュー |
---|
160 | else if (ocidKey as text) = "t" then |
---|
161 | set t of ocidRecordQuery to ocidValue |
---|
162 | set ocidMapType to ocidValue |
---|
163 | log "MapType:" & ocidMapType |
---|
164 | (* |
---|
165 | m (standard view) |
---|
166 | k (satellite view) |
---|
167 | h (hybrid view) |
---|
168 | r (transit view) |
---|
169 | goole |
---|
170 | map_action=pano |
---|
171 | map_action=map |
---|
172 | basemap=satellite |
---|
173 | terrain |
---|
174 | roadmap |
---|
175 | *) |
---|
176 | #################################### |
---|
177 | #########dirflg 移動方法 |
---|
178 | else if (ocidKey as text) = "dirflg" then |
---|
179 | set dirflg of ocidRecordQuery to ocidValue |
---|
180 | set ocidDirflgType to ocidValue |
---|
181 | log "DirflgType:" & ocidDirflgType |
---|
182 | (* |
---|
183 | d (by car) |
---|
184 | w (by foot) |
---|
185 | r (by public transit) |
---|
186 | |
---|
187 | goole |
---|
188 | travelmode=driving |
---|
189 | walking |
---|
190 | transit |
---|
191 | *) |
---|
192 | |
---|
193 | #########Dirflg Parameters 出発点 |
---|
194 | else if (ocidKey as text) = "saddr" then |
---|
195 | set saddr of ocidRecordQuery to ocidValue |
---|
196 | set strSaddrEnc to ocidValue as text |
---|
197 | set ocidSaddrEnc to ocidValue's stringByRemovingPercentEncoding |
---|
198 | log "StartingPoint:" & ocidSaddrEnc as text |
---|
199 | |
---|
200 | #########Destination 到着店 |
---|
201 | else if (ocidKey as text) = "daddr" then |
---|
202 | set daddr of ocidRecordQuery to ocidValue |
---|
203 | set strDaddrEnc to ocidValue as text |
---|
204 | set ocidDaddrEnc to ocidValue's stringByRemovingPercentEncoding |
---|
205 | log "DestinationPoint:" & ocidDaddrEnc as text |
---|
206 | |
---|
207 | #########Search Query 検索語句 |
---|
208 | else if (ocidKey as text) = "q" then |
---|
209 | set q of ocidRecordQuery to ocidValue |
---|
210 | set strRecordQuery to ocidValue as text |
---|
211 | set ocidSearchQueryEnc to ocidValue's stringByRemovingPercentEncoding |
---|
212 | log "SearchQuery" & ocidSearchQueryEnc as text |
---|
213 | |
---|
214 | #################################### |
---|
215 | #########語句検索時の周辺情報の有無による分岐 |
---|
216 | |
---|
217 | else if (ocidKey as text) = "sll" then |
---|
218 | set sll of ocidRecordQuery to ocidValue |
---|
219 | ####カンマでわけて緯度 経度に |
---|
220 | set ocidSearchArrayLL to (ocidValue's componentsSeparatedByString:",") |
---|
221 | log ocidSearchArrayLL as list |
---|
222 | ####最初の項目 |
---|
223 | set ocidNearLatitude to item 1 of ocidSearchArrayLL |
---|
224 | log "NearLatitude:" & ocidNearLatitude as text |
---|
225 | ####あとの項目 |
---|
226 | set ocidNearLongitude to item 2 of ocidSearchArrayLL |
---|
227 | log "NearNearLongitude:" & ocidNearLongitude as text |
---|
228 | |
---|
229 | else if (ocidKey as text) = "spn" then |
---|
230 | ####周囲情報の範囲 |
---|
231 | set spn of ocidRecordQuery to ocidValue |
---|
232 | |
---|
233 | |
---|
234 | #################################### |
---|
235 | #########during search周辺 位置情報 緯度 経度 |
---|
236 | |
---|
237 | else if (ocidKey as text) = "near" then |
---|
238 | set near of ocidRecordQuery to ocidValue |
---|
239 | ####カンマでわけて緯度 経度に |
---|
240 | set ocidNearArrayLL to (ocidValue's componentsSeparatedByString:",") |
---|
241 | log ocidNearArrayLL as list |
---|
242 | ###最初の項目 |
---|
243 | set ocidNearLatitude to item 1 of ocidNearArrayLL |
---|
244 | log "NearLatitude:" & ocidNearLatitude as text |
---|
245 | ###あとの項目 |
---|
246 | set ocidNearLongitude to item 2 of ocidNearArrayLL |
---|
247 | log "NearNearLongitude:" & ocidNearLongitude as text |
---|
248 | |
---|
249 | #################################### |
---|
250 | #########ガイド時のug |
---|
251 | else if (ocidKey as text) = "ug" then |
---|
252 | set ug of ocidRecordQuery to ocidValue |
---|
253 | |
---|
254 | end if |
---|
255 | |
---|
256 | end repeat |
---|
257 | |
---|
258 | log ocidRecordQuery as record |
---|
259 | objMe's NSLog("■:osascript: RecordQuery Done") |
---|
260 | ##################################################### |
---|
261 | #####QRコード保存要ファイル名 |
---|
262 | if (q of ocidRecordQuery as text) is not "" then |
---|
263 | ###検索語句あり |
---|
264 | if (count of (ocidSearchQueryEnc as text)) < 8 then |
---|
265 | set strQueryEnc to (ocidSearchQueryEnc as text) as text |
---|
266 | else |
---|
267 | set strQueryEnc to characters 1 thru 8 of (ocidSearchQueryEnc as text) as text |
---|
268 | end if |
---|
269 | set strFileName to ("" & strQueryEnc & ".png") |
---|
270 | objMe's NSLog("■:osascript: ocidSearchQueryEnc " & (ocidSearchQueryEnc as text) & "") |
---|
271 | |
---|
272 | else if (daddr of ocidRecordQuery as text) is not "" then |
---|
273 | ###行き先語句あり |
---|
274 | set strDaddrEnc to characters 1 thru 8 of (ocidDaddrEnc as text) as text |
---|
275 | set strFileName to ("" & strDaddrEnc & ".png") |
---|
276 | objMe's NSLog("■:osascript: ocidDaddrEnc " & (ocidDaddrEnc as text) & "") |
---|
277 | else |
---|
278 | ###語句の無い場合は日付をファイル名にする |
---|
279 | set strDateFormat to "yyyy年MMMMdd日hh時mm分" as text |
---|
280 | set ocidForMatter to objMe's NSDateFormatter's alloc()'s init() |
---|
281 | ocidForMatter's setLocale:(objMe's NSLocale's localeWithLocaleIdentifier:"ja_JP_POSIX") |
---|
282 | ocidForMatter's setDateFormat:(strDateFormat) |
---|
283 | set objDate to (current date) |
---|
284 | set strDateTime to (ocidForMatter's stringFromDate:(objDate)) as text |
---|
285 | set strFileName to ("" & strDateTime & ".png") |
---|
286 | end if |
---|
287 | |
---|
288 | #################################################### |
---|
289 | #########対応アプリの分岐 |
---|
290 | ###ホスト名を取り出し |
---|
291 | set ocidHostUrl to ocidURL's |host| |
---|
292 | log className() of ocidHostUrl as text |
---|
293 | --> __NSCFString |
---|
294 | log ocidHostUrl as text |
---|
295 | #################################### |
---|
296 | ###ホストによる分岐 |
---|
297 | if (ocidHostUrl as text) is "guides.apple.com" then |
---|
298 | -->このままの値でバーコードを作成する |
---|
299 | set listButtonAset to {"AppleMapガイド用"} as list |
---|
300 | set strAlertMes to "ガイドリンクはAppleMap専用です" |
---|
301 | |
---|
302 | else if (ocidHostUrl as text) is "collections.apple.com" then |
---|
303 | -->コレクションは現在は『ガイド』になった? |
---|
304 | set listButtonAset to {"AppleMapガイド用"} as list |
---|
305 | set strAlertMes to "ガイドリンクはAppleMap専用です" |
---|
306 | |
---|
307 | else if (ocidHostUrl as text) is "maps.apple.com" then |
---|
308 | -->ガイド以外 |
---|
309 | -->処理する |
---|
310 | #################################### |
---|
311 | ###内容によっての分岐 |
---|
312 | if (ll of ocidRecordQuery as text) is not "" then |
---|
313 | ######緯度経度がある場合 |
---|
314 | set listButtonAset to {"AppleMap用", "GoogleMap用", "GeoQR"} as list |
---|
315 | set strAlertMes to "GeoQRは対応していない機種やアプリがあります" |
---|
316 | |
---|
317 | else if (q of ocidRecordQuery as text) is not "" then |
---|
318 | ######検索語句がある場合 |
---|
319 | set listButtonAset to {"AppleMap用", "GoogleMap用", "汎用"} as list |
---|
320 | set strAlertMes to "iOS用AppleMapのQRコードを作成する OR 一般的なQRコードを作成する" |
---|
321 | |
---|
322 | else if (daddr of ocidRecordQuery as text) is not "" then |
---|
323 | set listButtonAset to {"AppleMap経路", "GoogleMap経路"} as list |
---|
324 | set strAlertMes to "経路情報用のMapになります" |
---|
325 | |
---|
326 | else |
---|
327 | ######緯度経度無し検索語句無しだとAppleMapのみ |
---|
328 | set listButtonAset to {"AppleMap用のみ"} as list |
---|
329 | set strAlertMes to "ガイドリンクはAppleMap専用です" |
---|
330 | |
---|
331 | end if |
---|
332 | end if |
---|
333 | ############################################## |
---|
334 | log listButtonAset |
---|
335 | try |
---|
336 | set objAns to (display alert "どちら用のQRコードを作成しますか?" message strAlertMes default button 1 buttons listButtonAset) |
---|
337 | on error |
---|
338 | log "エラーしました" |
---|
339 | return |
---|
340 | end try |
---|
341 | |
---|
342 | set objResponse to (button returned of objAns) as text |
---|
343 | ############################################## |
---|
344 | |
---|
345 | if objResponse is "GeoQR" then |
---|
346 | ### 緯度経度でGEOバーコード 対応機種に制限がある場合あり |
---|
347 | set theChl to ("GEO:" & (ocidLatitude as text) & "," & (ocidLongitude as text) & "," & (z of ocidRecordQuery as text) & "") as text |
---|
348 | ###経路情報 Map |
---|
349 | else if objResponse is "AppleMap経路" then |
---|
350 | set theChl to ("http://maps.apple.com/?daddr=" & (ocidDaddrEnc as text) & "&saddr=" & (ocidSaddrEnc as text) & "") as text |
---|
351 | ###経路情報 Google |
---|
352 | else if objResponse is "GoogleMap経路" then |
---|
353 | set theChl to ("https://www.google.com/maps/?daddr=" & (ocidDaddrEnc as text) & "&saddr=" & (ocidSaddrEnc as text) & "") as text |
---|
354 | ####AppleMapのガイドリンク |
---|
355 | else if objResponse is "AppleMapガイド用" then |
---|
356 | set theChl to ("" & strURL & "") as text |
---|
357 | |
---|
358 | else if objResponse is "GoogleMap用" then |
---|
359 | ############################################## |
---|
360 | ###GoogleMap用の小数点以下の桁揃え |
---|
361 | set theLatitude to (ocidLatitude as text) |
---|
362 | set AppleScript's text item delimiters to "." |
---|
363 | set listLatitude to every text item of theLatitude as list |
---|
364 | set AppleScript's text item delimiters to "" |
---|
365 | set strLatitudeInt to text item 1 of listLatitude as text |
---|
366 | set strLatitudeDecimal to text item 2 of listLatitude as text |
---|
367 | set strLatitudeDecimal to (text 1 through 7 of (strLatitudeDecimal & "000000000")) as text |
---|
368 | set theLatitude to ("" & strLatitudeInt & "." & strLatitudeDecimal & "") |
---|
369 | |
---|
370 | set theLongitude to (ocidLongitude as text) |
---|
371 | set AppleScript's text item delimiters to "." |
---|
372 | set listLongitude to every text item of theLongitude as list |
---|
373 | set AppleScript's text item delimiters to "" |
---|
374 | set strLongitudeInt to text item 1 of listLongitude as text |
---|
375 | set strLongitudeDecimal to text item 2 of listLongitude as text |
---|
376 | set strLongitudeDecimal to (text 1 through 7 of (strLongitudeDecimal & "000000000")) as text |
---|
377 | set theLongitude to ("" & strLongitudeInt & "." & strLongitudeDecimal & "") |
---|
378 | |
---|
379 | set theGooglemapParts to ("@" & theLatitude & "," & theLongitude & "," & (z of ocidRecordQuery as text) & "z") |
---|
380 | |
---|
381 | set theChl to ("https://www.google.com/maps/" & theGooglemapParts & "") as text |
---|
382 | else |
---|
383 | set theChl to ("http://maps.apple.com/?q=" & (ocidLatitude as text) & "," & (ocidLongitude as text) & "," & (z of ocidRecordQuery as text) & "z") as text |
---|
384 | end if |
---|
385 | |
---|
386 | |
---|
387 | ############################################## |
---|
388 | log theChl |
---|
389 | |
---|
390 | ###フォルダのパス |
---|
391 | ###ピクチャーフォルダのパス |
---|
392 | tell application "Finder" |
---|
393 | set aliasDirPath to (path to pictures folder from user domain) as alias |
---|
394 | set strDirPath to POSIX path of aliasDirPath as text |
---|
395 | end tell |
---|
396 | ####フォルダ名 |
---|
397 | set strFolderName to "QRcode" as text |
---|
398 | set strDirPath to ("" & strDirPath & strFolderName & "") as text |
---|
399 | ###NSStringテキスト |
---|
400 | set ocidDirPath to objNSString's stringWithString:strDirPath |
---|
401 | ###フォルダを作る |
---|
402 | ###途中のフォルダも作る-->true |
---|
403 | set boolMakeNewFolder to (objFileManager's createDirectoryAtPath:ocidDirPath withIntermediateDirectories:true attributes:(missing value) |error| :(missing value)) |
---|
404 | |
---|
405 | ####ファイルパス |
---|
406 | set strSaveFilePath to ("" & strDirPath & "/" & strFileName & "") as text |
---|
407 | |
---|
408 | objMe's NSLog("■:osascript: strSaveFilePath" & strSaveFilePath & "") |
---|
409 | |
---|
410 | ############################################## |
---|
411 | set strInputText to theChl as text |
---|
412 | ####テキストをNSStringに |
---|
413 | set ocidInputString to objNSString's stringWithString:strInputText |
---|
414 | ####テキストをUTF8に |
---|
415 | set ocidUtf8InputString to ocidInputString's dataUsingEncoding:(objMe's NSUTF8StringEncoding) |
---|
416 | ####CIQRCodeGenerator初期化 |
---|
417 | set ocidQRcodeImage to objMe's CIFilter's filterWithName:"CIQRCodeGenerator" |
---|
418 | ocidQRcodeImage's setDefaults() |
---|
419 | ###テキスト設定 |
---|
420 | ocidQRcodeImage's setValue:ocidUtf8InputString forKey:"inputMessage" |
---|
421 | ###読み取り誤差値設定L, M, Q, H |
---|
422 | ocidQRcodeImage's setValue:"Q" forKey:"inputCorrectionLevel" |
---|
423 | ###QRコード本体のイメージ |
---|
424 | set ocidCIImage to ocidQRcodeImage's outputImage() |
---|
425 | -->ここで生成されるのはQRのセルが1x1pxの最小サイズ |
---|
426 | ###QRコードの縦横取得 |
---|
427 | set ocidCIImageDimension to ocidCIImage's extent() |
---|
428 | set ocidCIImageWidth to (item 1 of item 2 of ocidCIImageDimension) as integer |
---|
429 | set ocidCIImageHight to (item 2 of item 2 of ocidCIImageDimension) as integer |
---|
430 | ###最終的に出力したいpxサイズ |
---|
431 | set numScaleMax to 720 |
---|
432 | ###整数で拡大しないとアレなので↑の値のニアなサイズになります |
---|
433 | set numWidth to ((numScaleMax / ocidCIImageWidth) div 1) as integer |
---|
434 | set numHight to ((numScaleMax / ocidCIImageHight) div 1) as integer |
---|
435 | ###↑サイズの拡大縮小する場合はここで値を調整すれば良い |
---|
436 | ####変換スケール作成-->拡大 |
---|
437 | set recordScalse to objMe's CGAffineTransform's CGAffineTransformMakeScale(numWidth, numHight) |
---|
438 | ##変換スケールを適応(元のサイズに元のサイズのスケール適応しても意味ないけど |
---|
439 | set ocidCIImageScaled to ocidCIImage's imageByApplyingTransform:recordScalse |
---|
440 | #######元のセルが1x1pxの最小サイズで出したいときはここで処理 |
---|
441 | ##set ocidCIImageScaled to ocidCIImage |
---|
442 | ###イメージデータを展開 |
---|
443 | set ocidNSCIImageRep to objMe's NSCIImageRep's imageRepWithCIImage:ocidCIImageScaled |
---|
444 | ###出力用のイメージの初期化 |
---|
445 | set ocidNSImageScaled to objMe's NSImage's alloc()'s initWithSize:(ocidNSCIImageRep's |size|()) |
---|
446 | ###イメージデータを合成 |
---|
447 | ocidNSImageScaled's addRepresentation:ocidNSCIImageRep |
---|
448 | ###出来上がったデータはOS_dispatch_data |
---|
449 | set ocidOsDispatchData to ocidNSImageScaled's TIFFRepresentation() |
---|
450 | ####NSBitmapImageRepに |
---|
451 | set ocidNSBitmapImageRep to objMe's NSBitmapImageRep's imageRepWithData:ocidOsDispatchData |
---|
452 | ################################################################# |
---|
453 | ###quiet zone用に画像をパディングする |
---|
454 | set numPadWidth to ((ocidCIImageWidth * numWidth) + (numWidth * 6)) as integer |
---|
455 | set numPadHight to ((ocidCIImageHight * numHight) + (numHight * 6)) as integer |
---|
456 | ###左右に3セル分づつ余白 quiet zoneを足す |
---|
457 | ####まずは元のQRコードのサイズに6セルサイズ分足したサイズの画像を作って |
---|
458 | set ocidNSBitmapImagePadRep to (objMe's NSBitmapImageRep's alloc()'s initWithBitmapDataPlanes:(missing value) pixelsWide:numPadWidth pixelsHigh:numPadHight bitsPerSample:8 samplesPerPixel:4 hasAlpha:true isPlanar:false colorSpaceName:(objMe's NSCalibratedRGBColorSpace) bitmapFormat:(objMe's NSAlphaFirstBitmapFormat) bytesPerRow:0 bitsPerPixel:32) |
---|
459 | ###初期化 |
---|
460 | objMe's NSGraphicsContext's saveGraphicsState() |
---|
461 | ###ビットマップイメージ |
---|
462 | (objMe's NSGraphicsContext's setCurrentContext:(objMe's NSGraphicsContext's graphicsContextWithBitmapImageRep:ocidNSBitmapImagePadRep)) |
---|
463 | ###塗り色を『白』に指定して |
---|
464 | objMe's NSColor's whiteColor()'s |set|() |
---|
465 | ##画像にする |
---|
466 | objMe's NSRectFill({origin:{x:0, y:0}, |size|:{width:numPadWidth, height:numPadHight}}) |
---|
467 | ###出来上がった画像にQRバーコードを左右3セル分ずらした位置にCompositeSourceOverする |
---|
468 | ocidNSBitmapImageRep's drawInRect:{origin:{x:(numWidth * 3), y:(numHight * 3)}, |size|:{width:numPadWidth, Hight:numPadHight}} fromRect:{origin:{x:0, y:0}, |size|:{width:numPadWidth, height:numPadHight}} operation:(objMe's NSCompositeSourceOver) fraction:1.0 respectFlipped:true hints:(missing value) |
---|
469 | ####画像作成終了 |
---|
470 | objMe's NSGraphicsContext's restoreGraphicsState() |
---|
471 | objMe's NSLog("■:osascript: restoreGraphicsState") |
---|
472 | ################################################################# |
---|
473 | |
---|
474 | ####JPEG用の圧縮プロパティ |
---|
475 | ##set ocidNSSingleEntryDictionary to objMe's NSDictionary's dictionaryWithObject:1 forKey:(objMe's NSImageCompressionFactor) |
---|
476 | ####PNG用の圧縮プロパティ |
---|
477 | set ocidNSSingleEntryDictionary to objMe's NSDictionary's dictionaryWithObject:true forKey:(objMe's NSImageInterlaced) |
---|
478 | |
---|
479 | #####出力イメージへ変換 |
---|
480 | set ocidNSInlineData to (ocidNSBitmapImagePadRep's representationUsingType:(objMe's NSBitmapImageFileTypePNG) |properties|:ocidNSSingleEntryDictionary) |
---|
481 | |
---|
482 | ######インラインデータをファイルに書き出し |
---|
483 | set boolMakeQrCode to (ocidNSInlineData's writeToFile:strSaveFilePath atomically:true) |
---|
484 | |
---|
485 | set aliasDirPath to POSIX file strDirPath as alias |
---|
486 | ###保存場所を開いて |
---|
487 | tell application "Finder" |
---|
488 | select aliasDirPath |
---|
489 | end tell |
---|
490 | ####プレビューに表示 |
---|
491 | tell application "Preview" |
---|
492 | launch |
---|
493 | activate |
---|
494 | open aliasDirPath |
---|
495 | end tell |
---|
496 | |
---|
497 | objMe's NSLog("■:osascript: Done") |
---|
498 | set theURL to "" |
---|
499 | set the clipboard to theURL |
---|
500 | set ocidNSInlineData to "" |
---|
501 | set ocidNSBitmapImagePadRep to "" |
---|
502 | |
---|
503 | |
---|
504 | return true |
---|
505 | |
---|
506 | |
---|
507 | to doCopyMap() |
---|
508 | tell application "System Events" |
---|
509 | launch |
---|
510 | end tell |
---|
511 | tell application "Maps" |
---|
512 | activate |
---|
513 | end tell |
---|
514 | try |
---|
515 | tell application "System Events" |
---|
516 | tell process "Maps" |
---|
517 | ## get every menu bar |
---|
518 | tell menu bar 1 |
---|
519 | ## get every menu bar item |
---|
520 | tell menu bar item "編集" |
---|
521 | ## get every menu bar item |
---|
522 | tell menu "編集" |
---|
523 | ## get every menu item |
---|
524 | tell menu item "リンクをコピー" |
---|
525 | click |
---|
526 | end tell |
---|
527 | end tell |
---|
528 | end tell |
---|
529 | end tell |
---|
530 | end tell |
---|
531 | end tell |
---|
532 | on error |
---|
533 | tell application "System Events" |
---|
534 | tell process "Maps" |
---|
535 | get every menu bar |
---|
536 | tell menu bar 1 |
---|
537 | get every menu bar item |
---|
538 | tell menu bar item "編集" |
---|
539 | get every menu bar item |
---|
540 | tell menu "編集" |
---|
541 | get every menu item |
---|
542 | tell menu item "コピー" |
---|
543 | click |
---|
544 | end tell |
---|
545 | end tell |
---|
546 | end tell |
---|
547 | end tell |
---|
548 | end tell |
---|
549 | end tell |
---|
550 | end try |
---|
551 | end doCopyMap |
---|