001 | #! /usr/bin/env osascript |
---|
002 | ----+----1----+----2----+-----3----+----4----+----5----+----6----+----7 |
---|
003 | # |
---|
004 | # edgemac用URLのQRコード生成 |
---|
005 | # 前面タブのURLをQRコードにしてHTMLをつけて保存します |
---|
006 | # |
---|
007 | # com.cocolog-nifty.quicktimer.icefloe |
---|
008 | ----+----1----+----2----+-----3----+----4----+----5----+----6----+----7 |
---|
009 | use AppleScript version "2.8" |
---|
010 | use framework "Foundation" |
---|
011 | use framework "AppKit" |
---|
012 | use framework "CoreImage" |
---|
013 | use scripting additions |
---|
014 | |
---|
015 | property refMe : a reference to current application |
---|
016 | property refNSNotFound : a reference to 9.22337203685477E+18 + 5807 |
---|
017 | |
---|
018 | #################################### |
---|
019 | #アプリケーションのバンドルID |
---|
020 | set strBundleID to "com.microsoft.edgemac" |
---|
021 | ###エラー処理 |
---|
022 | tell application id strBundleID |
---|
023 | set numWindow to (count of every window) as integer |
---|
024 | end tell |
---|
025 | if numWindow = 0 then |
---|
026 | return "Windowが無いので処理できません" |
---|
027 | end if |
---|
028 | tell application "Microsoft Edge" |
---|
029 | tell front window |
---|
030 | tell active tab |
---|
031 | activate |
---|
032 | set strURL to URL as text |
---|
033 | end tell |
---|
034 | end tell |
---|
035 | end tell |
---|
036 | |
---|
037 | #################################### |
---|
038 | #URLをNSStringに |
---|
039 | set ocidURLStrings to refMe's NSString's stringWithString:(strURL) |
---|
040 | ###改行とタブだけは取っておく |
---|
041 | set ocidTextM to ocidURLStrings's stringByReplacingOccurrencesOfString:("\n") withString:("") |
---|
042 | set ocidTextM to ocidTextM's stringByReplacingOccurrencesOfString:("\r") withString:("") |
---|
043 | set ocidTextM to ocidTextM's stringByReplacingOccurrencesOfString:("\t") withString:("") |
---|
044 | set strText to ocidTextM as text |
---|
045 | ## |
---|
046 | set ocidURL to refMe's NSURL's alloc()'s initWithString:(strText) |
---|
047 | set strHostName to ocidURL's |host|() as text |
---|
048 | |
---|
049 | #################################### |
---|
050 | # QRコード保存先 NSPicturesDirectory |
---|
051 | set appFileManager to refMe's NSFileManager's defaultManager() |
---|
052 | set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSPicturesDirectory) inDomains:(refMe's NSUserDomainMask)) |
---|
053 | set ocidPicturesDirURL to ocidURLsArray's firstObject() |
---|
054 | set strSetValue to ("QRcode/URL/" & strHostName) as text |
---|
055 | set ocidSaveDirPathURL to ocidPicturesDirURL's URLByAppendingPathComponent:(strSetValue) isDirectory:(true) |
---|
056 | ##フォルダ作成 |
---|
057 | set ocidAttrDict to refMe's NSMutableDictionary's alloc()'s initWithCapacity:0 |
---|
058 | # 777-->511 755-->493 700-->448 766-->502 |
---|
059 | ocidAttrDict's setValue:(448) forKey:(refMe's NSFilePosixPermissions) |
---|
060 | set listDone to appFileManager's createDirectoryAtURL:(ocidSaveDirPathURL) withIntermediateDirectories:true attributes:(ocidAttrDict) |error| :(reference) |
---|
061 | if (item 1 of listDone) is true then |
---|
062 | #log "正常処理" |
---|
063 | else if (item 2 of listDone) ≠ (missing value) then |
---|
064 | set strErrorNO to (item 2 of listDone)'s code() as text |
---|
065 | set strErrorMes to (item 2 of listDone)'s localizedDescription() as text |
---|
066 | refMe's NSLog("■:" & strErrorNO & strErrorMes) |
---|
067 | return "エラーしました" & strErrorNO & strErrorMes |
---|
068 | end if |
---|
069 | # |
---|
070 | set ocidReadMePathURL to ocidPicturesDirURL's URLByAppendingPathComponent:("QRcode/URL/_このフォルダは削除しても大丈夫です.txt") isDirectory:(false) |
---|
071 | set ocidReadMeText to refMe's NSString's stringWithString:("このフォルダは削除しても大丈夫です") |
---|
072 | # |
---|
073 | set listDone to ocidReadMeText's writeToURL:(ocidReadMePathURL) atomically:(true) encoding:(refMe's NSUTF8StringEncoding) |error| :(reference) |
---|
074 | if (item 1 of listDone) is true then |
---|
075 | #log "正常処理" |
---|
076 | else if (item 2 of listDone) ≠ (missing value) then |
---|
077 | set strErrorNO to (item 2 of listDone)'s code() as text |
---|
078 | set strErrorMes to (item 2 of listDone)'s localizedDescription() as text |
---|
079 | refMe's NSLog("■:" & strErrorNO & strErrorMes) |
---|
080 | return "エラーしました" & strErrorNO & strErrorMes |
---|
081 | end if |
---|
082 | |
---|
083 | ###保存ファイル名 |
---|
084 | set strDateNo to doGetDateNo({"yyyyMMddhhmmss", 1}) |
---|
085 | set strSaveFileName to ("URL" & "." & strHostName & "." & strDateNo & ".png") as text |
---|
086 | set ocidSaveFilePathURL to ocidSaveDirPathURL's URLByAppendingPathComponent:(strSaveFileName) |
---|
087 | |
---|
088 | |
---|
089 | ###################################### |
---|
090 | ### 色決め 切り捨ての都合上指定のニア |
---|
091 | ###################################### |
---|
092 | #ダイアログを前面に出す |
---|
093 | set strName to (name of current application) as text |
---|
094 | if strName is "osascript" then |
---|
095 | tell application "Finder" to activate |
---|
096 | else |
---|
097 | tell current application to activate |
---|
098 | end if |
---|
099 | tell application "Finder" |
---|
100 | set the listRGB16bitColor to (choose color default color {0, 0, 0, 1}) as list |
---|
101 | end tell |
---|
102 | ##########Color Picker Value 16Bit |
---|
103 | set str16bitR to (item 1 of listRGB16bitColor) as text |
---|
104 | set str16bitG to (item 2 of listRGB16bitColor) as text |
---|
105 | set str16bitB to (item 3 of listRGB16bitColor) as text |
---|
106 | set str16bitA to 65535 as text |
---|
107 | #NSDecimalNumberに変換して計算 |
---|
108 | set ocidDecR to refMe's NSDecimalNumber's alloc()'s initWithString:(str16bitR) |
---|
109 | set ocidDecG to refMe's NSDecimalNumber's alloc()'s initWithString:(str16bitG) |
---|
110 | set ocidDecB to refMe's NSDecimalNumber's alloc()'s initWithString:(str16bitB) |
---|
111 | set ocidDecA to refMe's NSDecimalNumber's alloc()'s initWithString:(str16bitA) |
---|
112 | ##########Standard RGB Value 8Bit 整数で切り捨て |
---|
113 | set ocid16bit to refMe's NSDecimalNumber's alloc()'s initWithString:("256") |
---|
114 | set ocidMode to (refMe's NSRoundDown) |
---|
115 | set ocidBehaviors to (refMe's NSDecimalNumberHandler's decimalNumberHandlerWithRoundingMode:(ocidMode) scale:(0) raiseOnExactness:(false) raiseOnOverflow:(false) raiseOnUnderflow:(false) raiseOnDivideByZero:(false)) |
---|
116 | set ocid8bitR to (ocidDecR's decimalNumberByDividingBy:(ocid16bit) withBehavior:(ocidBehaviors)) |
---|
117 | set ocid8bitG to (ocidDecG's decimalNumberByDividingBy:(ocid16bit) withBehavior:(ocidBehaviors)) |
---|
118 | set ocid8bitB to (ocidDecB's decimalNumberByDividingBy:(ocid16bit) withBehavior:(ocidBehaviors)) |
---|
119 | set ocid8bitA to (ocidDecA's decimalNumberByDividingBy:(ocid16bit) withBehavior:(ocidBehaviors)) |
---|
120 | ##########NSColorValue Float |
---|
121 | set ocid8bit to refMe's NSDecimalNumber's alloc()'s initWithString:("255") |
---|
122 | # |
---|
123 | set ocidFloatR to (ocid8bitR's decimalNumberByDividingBy:(ocid8bit)) |
---|
124 | set ocidFloatG to (ocid8bitG's decimalNumberByDividingBy:(ocid8bit)) |
---|
125 | set ocidFloatB to (ocid8bitB's decimalNumberByDividingBy:(ocid8bit)) |
---|
126 | set ocidFloatA to (ocid8bitA's decimalNumberByDividingBy:(ocid8bit)) |
---|
127 | |
---|
128 | ##########12桁までで丸め |
---|
129 | set ocidMode to (refMe's NSRoundDown) |
---|
130 | set ocidBehaviors to (refMe's NSDecimalNumberHandler's decimalNumberHandlerWithRoundingMode:(ocidMode) scale:(12) raiseOnExactness:(false) raiseOnOverflow:(false) raiseOnUnderflow:(false) raiseOnDivideByZero:(false)) |
---|
131 | set ocidFloat12R to (ocidFloatR's decimalNumberByRoundingAccordingToBehavior:(ocidBehaviors)) |
---|
132 | set ocidFloat12G to (ocidFloatG's decimalNumberByRoundingAccordingToBehavior:(ocidBehaviors)) |
---|
133 | set ocidFloat12B to (ocidFloatB's decimalNumberByRoundingAccordingToBehavior:(ocidBehaviors)) |
---|
134 | set ocidFloat12A to (ocidFloatA's decimalNumberByRoundingAccordingToBehavior:(ocidBehaviors)) |
---|
135 | ## |
---|
136 | set numFloat12R to ocidFloat12R's floatValue() |
---|
137 | set numFloat12G to ocidFloat12G's floatValue() |
---|
138 | set numFloat12B to ocidFloat12B's floatValue() |
---|
139 | set numFloat12A to ocidFloat12A's floatValue() |
---|
140 | |
---|
141 | ####色指定 |
---|
142 | ## 色指定値はこちらを利用 |
---|
143 | ## https://quicktimer.cocolog-nifty.com/icefloe/2023/06/post-d68270.html |
---|
144 | ###色指定する場合 |
---|
145 | ## set ocidQrColor to refMe's CIColor's colorWithRed:0.1green:0.75blue:0.26 alpha:1.0 |
---|
146 | ###バーコードの色をここで定義 |
---|
147 | set ocidQrColor to refMe's CIColor's colorWithRed:(numFloat12R) green:(numFloat12G) blue:(numFloat12B) alpha:(numFloat12A) |
---|
148 | ############################# |
---|
149 | ### 【1】QRバーコード画像生成 |
---|
150 | ############################# |
---|
151 | ####テキストをNSStringに |
---|
152 | set ocidInputString to refMe's NSString's stringWithString:(strText) |
---|
153 | ####テキストをUTF8に |
---|
154 | set ocidUtf8InputString to ocidInputString's dataUsingEncoding:(refMe's NSUTF8StringEncoding) |
---|
155 | ####CIQRCodeGenerator初期化 |
---|
156 | set ocidQRcodeImage to refMe's CIFilter's filterWithName:("CIQRCodeGenerator") |
---|
157 | ocidQRcodeImage's setDefaults() |
---|
158 | ###テキスト設定 |
---|
159 | ocidQRcodeImage's setValue:ocidUtf8InputString forKey:("inputMessage") |
---|
160 | ###読み取り誤差値設定L, M, Q, H |
---|
161 | ocidQRcodeImage's setValue:"Q" forKey:("inputCorrectionLevel") |
---|
162 | ###QRコード本体のイメージ |
---|
163 | set ocidCIImage to ocidQRcodeImage's outputImage() |
---|
164 | -->ここで生成されるのはQRのセルが1x1pxの最小サイズ |
---|
165 | ############## |
---|
166 | ### 色の置き換え |
---|
167 | ### 置き換わる色=この場合は黒 |
---|
168 | set ocidBlackColor to refMe's CIColor's colorWithRed:1.0 green:1.0 blue:1.0 alpha:0.0 |
---|
169 | ###CIFalseColorで色を塗ります |
---|
170 | set ocidFilterColor to refMe's CIFilter's filterWithName:("CIFalseColor") |
---|
171 | ocidFilterColor's setDefaults() |
---|
172 | ocidFilterColor's setValue:ocidQrColor forKey:("inputColor0") |
---|
173 | ocidFilterColor's setValue:ocidBlackColor forKey:("inputColor1") |
---|
174 | ocidFilterColor's setValue:ocidCIImage forKey:("inputImage") |
---|
175 | ###フィルタをかけた画像をoutputImageから取り出します |
---|
176 | set ocidCIImage to ocidFilterColor's valueForKey:("outputImage") |
---|
177 | ###QRコードの縦横取得 |
---|
178 | set ocidCIImageDimension to ocidCIImage's extent() |
---|
179 | set ocidCIImageWidth to (item 1 of item 2 of ocidCIImageDimension) as integer |
---|
180 | set ocidCIImageHight to (item 2 of item 2 of ocidCIImageDimension) as integer |
---|
181 | ###最終的に出力したいpxサイズ |
---|
182 | set numScaleMax to 500 |
---|
183 | ###整数で拡大しないとアレなので↑の値のニアなサイズになります |
---|
184 | set numWidth to ((numScaleMax / ocidCIImageWidth) div 1) as integer |
---|
185 | set numHight to ((numScaleMax / ocidCIImageHight) div 1) as integer |
---|
186 | ###↑サイズの拡大縮小する場合はここで値を調整すれば良い |
---|
187 | ####変換スケール作成-->拡大 |
---|
188 | set recordScalse to refMe's CGAffineTransform's CGAffineTransformMakeScale(numWidth, numHight) |
---|
189 | ##変換スケールを適応(元のサイズに元のサイズのスケール適応しても意味ないけど |
---|
190 | set ocidCIImageScaled to ocidCIImage's imageByApplyingTransform:(recordScalse) |
---|
191 | #######元のセルが1x1pxの最小サイズで出したいときはここで処理 |
---|
192 | ##set ocidCIImageScaled to ocidCIImage |
---|
193 | ###イメージデータを展開 |
---|
194 | set ocidNSCIImageRep to refMe's NSCIImageRep's imageRepWithCIImage:(ocidCIImageScaled) |
---|
195 | ###出力用のイメージの初期化 |
---|
196 | set ocidNSImageScaled to refMe's NSImage's alloc()'s initWithSize:(ocidNSCIImageRep's |size|()) |
---|
197 | ###イメージデータを合成 |
---|
198 | ocidNSImageScaled's addRepresentation:(ocidNSCIImageRep) |
---|
199 | ###出来上がったデータはOS_dispatch_data |
---|
200 | set ocidOsDispatchData to ocidNSImageScaled's TIFFRepresentation() |
---|
201 | ####NSBitmapImageRepに |
---|
202 | set ocidQRImageRep to refMe's NSBitmapImageRep's imageRepWithData:(ocidOsDispatchData) |
---|
203 | |
---|
204 | ############################# |
---|
205 | ### 【2】QRコードの背景部 |
---|
206 | ###(ホワイトスペースパディング配慮) |
---|
207 | ############################# |
---|
208 | ##画像サイズ |
---|
209 | set numQRSize to 520 as integer |
---|
210 | ##画像生成開始 |
---|
211 | set ocidBitmapFormat to refMe's NSBitmapFormatAlphaFirst |
---|
212 | set ocidColorSpaceName to refMe's NSCalibratedRGBColorSpace |
---|
213 | ### NSBitmapImageRep |
---|
214 | set ocidCodeBaseRep to (refMe's NSBitmapImageRep's alloc()'s initWithBitmapDataPlanes:(missing value) pixelsWide:(numQRSize) pixelsHigh:(numQRSize) bitsPerSample:8 samplesPerPixel:4 hasAlpha:true isPlanar:false colorSpaceName:(ocidColorSpaceName) bitmapFormat:(ocidBitmapFormat) bytesPerRow:0 bitsPerPixel:32) |
---|
215 | ############################# |
---|
216 | ### 初期化 CodeBase |
---|
217 | refMe's NSGraphicsContext's saveGraphicsState() |
---|
218 | ###Context |
---|
219 | set ocidContext to (refMe's NSGraphicsContext's graphicsContextWithBitmapImageRep:(ocidCodeBaseRep)) |
---|
220 | ###生成された画像でNSGraphicsContext初期化 |
---|
221 | (refMe's NSGraphicsContext's setCurrentContext:(ocidContext)) |
---|
222 | ###ここが背景色の塗り色 |
---|
223 | ##色を個別に指定する場合 値は0が暗 1が明 |
---|
224 | set ocidSetColor to (refMe's NSColor's colorWithSRGBRed:(1) green:(1) blue:(1) alpha:(1.0)) |
---|
225 | ocidSetColor's |set|() |
---|
226 | ###画像生成 |
---|
227 | refMe's NSRectFill({origin:{x:0, y:0}, |size|:{width:(numQRSize), height:(numQRSize)}}) |
---|
228 | ####画像作成終了 |
---|
229 | refMe's NSGraphicsContext's restoreGraphicsState() |
---|
230 | ############################# |
---|
231 | ### 【3】QRバーコードパディング処理 |
---|
232 | ### 1で作ったQRバーコード画像を |
---|
233 | ### 2で作った画像にペースト |
---|
234 | ###(ホワイトスペースパディング配慮) |
---|
235 | ############################# |
---|
236 | ### |
---|
237 | set numPxWidth to ocidQRImageRep's pixelsWide() |
---|
238 | set numPxHight to ocidQRImageRep's pixelsHigh() |
---|
239 | ###画像合成位置計算パディング配慮 |
---|
240 | set numPadSize to (numQRSize - numPxWidth) / 2 as integer |
---|
241 | ############################# |
---|
242 | ### 初期化 CodeBase |
---|
243 | refMe's NSGraphicsContext's saveGraphicsState() |
---|
244 | ###Context |
---|
245 | set ocidContext to (refMe's NSGraphicsContext's graphicsContextWithBitmapImageRep:(ocidCodeBaseRep)) |
---|
246 | ###生成された画像でNSGraphicsContext初期化 |
---|
247 | (refMe's NSGraphicsContext's setCurrentContext:(ocidContext)) |
---|
248 | ###出来上がった画像にQRバーコードをCompositeSourceOverする |
---|
249 | ocidQRImageRep's drawInRect:{origin:{x:(numPadSize), y:(numPadSize)}, |size|:{width:(numPxWidth), Hight:(numPxWidth)}} fromRect:{origin:{x:0, y:0}, |size|:{width:(numPxWidth), height:(numPxHight)}} operation:(refMe's NSCompositeSourceOver) fraction:1.0 respectFlipped:true hints:(missing value) |
---|
250 | ####画像作成終了 |
---|
251 | refMe's NSGraphicsContext's restoreGraphicsState() |
---|
252 | ############################# |
---|
253 | ### 【4】最終的な出力画像生成 |
---|
254 | ### ArtBoardになる画像の生成 |
---|
255 | ############################# |
---|
256 | ### 背景 ARTBORD |
---|
257 | set ocidBitmapFormat to refMe's NSBitmapFormatAlphaFirst |
---|
258 | set ocidColorSpaceName to refMe's NSCalibratedRGBColorSpace |
---|
259 | ### NSBitmapImageRep |
---|
260 | set ocidArtBoardRep to (refMe's NSBitmapImageRep's alloc()'s initWithBitmapDataPlanes:(missing value) pixelsWide:(580) pixelsHigh:(680) bitsPerSample:8 samplesPerPixel:4 hasAlpha:true isPlanar:false colorSpaceName:(ocidColorSpaceName) bitmapFormat:(ocidBitmapFormat) bytesPerRow:0 bitsPerPixel:32) |
---|
261 | ############################# |
---|
262 | ### 初期化 ArtBoard |
---|
263 | refMe's NSGraphicsContext's saveGraphicsState() |
---|
264 | ###Context |
---|
265 | set ocidContext to (refMe's NSGraphicsContext's graphicsContextWithBitmapImageRep:(ocidArtBoardRep)) |
---|
266 | ###生成された画像でNSGraphicsContext初期化 |
---|
267 | (refMe's NSGraphicsContext's setCurrentContext:(ocidContext)) |
---|
268 | ###ここが背景色の塗り色 |
---|
269 | ##色を個別に指定する場合 値は0が暗 1が明 |
---|
270 | set ocidSetColor to (refMe's NSColor's colorWithSRGBRed:(numFloat12R) green:(numFloat12G) blue:(numFloat12B) alpha:(numFloat12A)) |
---|
271 | ## 透過の場合 |
---|
272 | ## set ocidSetColor to refMe's NSColor's clearColor() |
---|
273 | ## 白 |
---|
274 | ## set ocidSetColor to refMe's NSColor's whiteColor() |
---|
275 | ocidSetColor's |set|() |
---|
276 | ###画像生成 |
---|
277 | refMe's NSRectFill({origin:{x:0, y:0}, |size|:{width:(580), height:(680)}}) |
---|
278 | ####画像作成終了 |
---|
279 | refMe's NSGraphicsContext's restoreGraphicsState() |
---|
280 | ############################# |
---|
281 | ### 【5】QRコードペースト |
---|
282 | ### 3で作ったパディング済みQRコードを |
---|
283 | ### 4で作ったArtBoardにペースト |
---|
284 | ############################# |
---|
285 | ### 初期化 バーコードを ocidArtBoardRep にペースト |
---|
286 | refMe's NSGraphicsContext's saveGraphicsState() |
---|
287 | ###ビットマップイメージ |
---|
288 | (refMe's NSGraphicsContext's setCurrentContext:(refMe's NSGraphicsContext's graphicsContextWithBitmapImageRep:(ocidArtBoardRep))) |
---|
289 | ###画像合成位置計算 |
---|
290 | ###左右位置センタリング |
---|
291 | set numLeftPad to ((580 - numQRSize) / 2) as integer |
---|
292 | ###左右のパディング幅と同じサイズで上部パディング |
---|
293 | set numbottomPad to (680 - numQRSize - numLeftPad) |
---|
294 | ###出来上がった画像にQRバーコードを左右3セル分ずらした位置にCompositeSourceOverする |
---|
295 | ocidCodeBaseRep's drawInRect:{origin:{x:(numLeftPad), y:(numbottomPad)}, |size|:{width:numQRSize, Hight:numQRSize}} fromRect:{origin:{x:0, y:0}, |size|:{width:numQRSize, height:numQRSize}} operation:(refMe's NSCompositeSourceOver) fraction:1.0 respectFlipped:true hints:(missing value) |
---|
296 | ####画像作成終了 |
---|
297 | refMe's NSGraphicsContext's restoreGraphicsState() |
---|
298 | ############################# |
---|
299 | ### 【6】テキスト描画 |
---|
300 | ### 5で生成された画像に対して |
---|
301 | ### テキスト画像を描画する |
---|
302 | ############################# |
---|
303 | ###フォント初期化 |
---|
304 | set appFontManager to refMe's NSFontManager |
---|
305 | set appSharedMaanager to appFontManager's sharedFontManager() |
---|
306 | ###設定用のレコード |
---|
307 | set ocidTextAttr to (refMe's NSMutableDictionary's alloc()'s initWithCapacity:0) |
---|
308 | ###共通項目 |
---|
309 | set ocidStyle to refMe's NSParagraphStyle's defaultParagraphStyle |
---|
310 | (ocidTextAttr's setObject:(ocidStyle) forKey:(refMe's NSParagraphStyleAttributeName)) |
---|
311 | ###画像の明暗判定 |
---|
312 | set numColorBD to (numFloat12R + numFloat12G + numFloat12B) as number |
---|
313 | log numColorBD |
---|
314 | if numColorBD > 3.5 then |
---|
315 | ##明るいバーコード色の時は文字色は黒 |
---|
316 | set ocidTextColor to (refMe's NSColor's colorWithSRGBRed:(0) green:(0) blue:(0) alpha:(1.0)) |
---|
317 | (ocidTextAttr's setObject:(ocidTextColor) forKey:(refMe's NSForegroundColorAttributeName)) |
---|
318 | ##文字色黒の時はドロップシャドウを入れる |
---|
319 | set ocidShadow to refMe's NSShadow's alloc()'s init() |
---|
320 | set ocidShadowColor to (ocidTextColor's colorWithAlphaComponent:0.8) |
---|
321 | (ocidShadow's setShadowColor:(ocidShadowColor)) |
---|
322 | (ocidShadow's setShadowOffset:(refMe's NSMakeSize(1, -1))) |
---|
323 | (ocidShadow's setShadowBlurRadius:4) |
---|
324 | (ocidTextAttr's setObject:(ocidShadow) forKey:(refMe's NSShadowAttributeName)) |
---|
325 | else |
---|
326 | ##暗いバーコード色の時は文字色白 |
---|
327 | set ocidTextColor to (refMe's NSColor's colorWithSRGBRed:(1) green:(1) blue:(1) alpha:(1.0)) |
---|
328 | (ocidTextAttr's setObject:(ocidTextColor) forKey:(refMe's NSForegroundColorAttributeName)) |
---|
329 | end if |
---|
330 | |
---|
331 | ############################# |
---|
332 | ###初期化 |
---|
333 | refMe's NSGraphicsContext's saveGraphicsState() |
---|
334 | ####NSGraphicsContextは透明アートボード |
---|
335 | set ocidContext to (refMe's NSGraphicsContext's graphicsContextWithBitmapImageRep:(ocidArtBoardRep)) |
---|
336 | ###ArtBoardでNSGraphicsContext初期化 |
---|
337 | (refMe's NSGraphicsContext's setCurrentContext:(ocidContext)) |
---|
338 | ############## |
---|
339 | set ocidText to (refMe's NSString's stringWithString:("URL LINK QR")) |
---|
340 | ## |
---|
341 | set ocidFont to (refMe's NSFont's fontWithName:("Helvetica-Bold") |size|:(52)) |
---|
342 | (ocidTextAttr's setObject:(ocidFont) forKey:(refMe's NSFontAttributeName)) |
---|
343 | (ocidTextAttr's setObject:(-1.8) forKey:(refMe's NSKernAttributeName)) |
---|
344 | set ocidTextOrigin to refMe's NSMakePoint((30), (45)) |
---|
345 | (ocidText's drawAtPoint:(ocidTextOrigin) withAttributes:(ocidTextAttr)) |
---|
346 | ############## |
---|
347 | ###URLの文字数調べて |
---|
348 | set numCntChar to ((count of (every character of strText)) as list) as integer |
---|
349 | ### |
---|
350 | set numFontSize to (round of (24 * (40 / numCntChar)) rounding down) as integer |
---|
351 | (* |
---|
352 | フォントサイズ24で半角40文字程度入るので |
---|
353 | 渡されたURLの文字数からフォントサイズを推定 小数点以下は切り捨て |
---|
354 | *) |
---|
355 | if numFontSize > 24 then |
---|
356 | set numFontSize to 24 as integer |
---|
357 | end if |
---|
358 | ### |
---|
359 | set ocidText to (refMe's NSString's stringWithString:(strText)) |
---|
360 | # set ocidFont to (refMe's NSFont's fontWithName:("ヒラギノ角ゴシック W3") |size|:(numFontSize)) |
---|
361 | ## |
---|
362 | set ocidFont to (refMe's NSFont's fontWithName:("CourierNewPSMT") |size|:(numFontSize)) |
---|
363 | (ocidTextAttr's setObject:(ocidFont) forKey:(refMe's NSFontAttributeName)) |
---|
364 | (ocidTextAttr's setObject:(-1) forKey:(refMe's NSKernAttributeName)) |
---|
365 | set ocidTextOrigin to refMe's NSMakePoint((35), (15)) |
---|
366 | (ocidText's drawAtPoint:(ocidTextOrigin) withAttributes:(ocidTextAttr)) |
---|
367 | (* |
---|
368 | ここのキャラクターIDは |
---|
369 | こちらを参照してください |
---|
370 | https://quicktimer.cocolog-nifty.com/icefloe/cat76056068/index.html |
---|
371 | *) |
---|
372 | set strIconText to (character id 1049758) as text |
---|
373 | set ocidText to (refMe's NSString's stringWithString:(strIconText)) |
---|
374 | set ocidFont to (refMe's NSFont's fontWithName:("SFPro-Bold") |size|:(72)) |
---|
375 | (ocidTextAttr's setObject:(ocidFont) forKey:(refMe's NSFontAttributeName)) |
---|
376 | (ocidTextAttr's setObject:(0) forKey:(refMe's NSKernAttributeName)) |
---|
377 | set ocidTextOrigin to refMe's NSMakePoint((460), (30)) |
---|
378 | (ocidText's drawAtPoint:(ocidTextOrigin) withAttributes:(ocidTextAttr)) |
---|
379 | |
---|
380 | ####画像作成終了 |
---|
381 | refMe's NSGraphicsContext's restoreGraphicsState() |
---|
382 | |
---|
383 | ############################# |
---|
384 | ### 【7】画像データ保存 |
---|
385 | ### 6で生成された画像に対を |
---|
386 | ### 指定のフォルダに保存する |
---|
387 | ############################# |
---|
388 | ####PNG用の圧縮プロパティ |
---|
389 | set ocidNSSingleEntryDictionary to refMe's NSDictionary's dictionaryWithObject:true forKey:(refMe's NSImageInterlaced) |
---|
390 | #####出力イメージへ変換 |
---|
391 | set ocidNSInlineData to (ocidArtBoardRep's representationUsingType:(refMe's NSBitmapImageFileTypePNG) |properties|:ocidNSSingleEntryDictionary) |
---|
392 | (* |
---|
393 | NSBitmapImageFileTypeJPEG |
---|
394 | NSBitmapImageFileTypePNG |
---|
395 | NSBitmapImageFileTypeGIF |
---|
396 | NSBitmapImageFileTypeBMP |
---|
397 | NSBitmapImageFileTypeTIFF |
---|
398 | NSBitmapImageFileTypeJPEG2000 |
---|
399 | *) |
---|
400 | ### 保存 |
---|
401 | set ocidOption to (refMe's NSDataWritingAtomic) |
---|
402 | set listDone to ocidNSInlineData's writeToURL:(ocidSaveFilePathURL) options:(ocidOption) |error| :(reference) |
---|
403 | if (item 1 of listDone) is true then |
---|
404 | log "保存しました" |
---|
405 | set aliasSaveFilePath to (ocidSaveFilePathURL's absoluteURL()) as alias |
---|
406 | else if (item 2 of listDone) ≠ (missing value) then |
---|
407 | log (item 2 of listDone)'s localizedFailureReason() as text |
---|
408 | return "保存に失敗しました" |
---|
409 | end if |
---|
410 | |
---|
411 | |
---|
412 | |
---|
413 | ############################# |
---|
414 | ### HTML生成 不要な場合は削除可 |
---|
415 | doMakeHTML(ocidSaveFilePathURL, strText) |
---|
416 | |
---|
417 | ############################# |
---|
418 | ### 【8】表示 |
---|
419 | ############################# |
---|
420 | (* |
---|
421 | ###Preview で開く |
---|
422 | tell application "Preview" |
---|
423 | launch |
---|
424 | activate |
---|
425 | open file aliasSaveFilePath |
---|
426 | end tell |
---|
427 | *) |
---|
428 | ##################### |
---|
429 | ### Finderで保存先を開く |
---|
430 | set appSharedWorkspace to refMe's NSWorkspace's sharedWorkspace() |
---|
431 | set boolDone to appSharedWorkspace's selectFile:(ocidSaveFilePathURL's |path|()) inFileViewerRootedAtPath:(ocidSaveDirPathURL's |path|()) |
---|
432 | if boolDone is true then |
---|
433 | return "処理正常終了" |
---|
434 | else if boolDone is false then |
---|
435 | log (item 2 of listDone)'s localizedFailureReason() as text |
---|
436 | return "ファイルのオープンに失敗しました" |
---|
437 | end if |
---|
438 | return |
---|
439 | |
---|
440 | ################################ |
---|
441 | # 日付 doGetDateNo(argDateFormat,argCalendarNO) |
---|
442 | # argCalendarNO 1 NSCalendarIdentifierGregorian 西暦 |
---|
443 | # argCalendarNO 2 NSCalendarIdentifierJapanese 和暦 |
---|
444 | ################################ |
---|
445 | to doGetDateNo({argDateFormat, argCalendarNO}) |
---|
446 | ##渡された値をテキストで確定させて |
---|
447 | set strDateFormat to argDateFormat as text |
---|
448 | set intCalendarNO to argCalendarNO as integer |
---|
449 | ###日付情報の取得 |
---|
450 | set ocidDate to current application's NSDate's |date|() |
---|
451 | ###日付のフォーマットを定義(日本語) |
---|
452 | set ocidFormatterJP to current application's NSDateFormatter's alloc()'s init() |
---|
453 | ###和暦 西暦 カレンダー分岐 |
---|
454 | if intCalendarNO = 1 then |
---|
455 | set ocidCalendarID to (current application's NSCalendarIdentifierGregorian) |
---|
456 | else if intCalendarNO = 2 then |
---|
457 | set ocidCalendarID to (current application's NSCalendarIdentifierJapanese) |
---|
458 | else |
---|
459 | set ocidCalendarID to (current application's NSCalendarIdentifierISO8601) |
---|
460 | end if |
---|
461 | set ocidCalendarJP to current application's NSCalendar's alloc()'s initWithCalendarIdentifier:(ocidCalendarID) |
---|
462 | set ocidTimezoneJP to current application's NSTimeZone's alloc()'s initWithName:("Asia/Tokyo") |
---|
463 | set ocidLocaleJP to current application's NSLocale's alloc()'s initWithLocaleIdentifier:("ja_JP_POSIX") |
---|
464 | ###設定 |
---|
465 | ocidFormatterJP's setTimeZone:(ocidTimezoneJP) |
---|
466 | ocidFormatterJP's setLocale:(ocidLocaleJP) |
---|
467 | ocidFormatterJP's setCalendar:(ocidCalendarJP) |
---|
468 | # ocidFormatterJP's setDateStyle:(current application's NSDateFormatterNoStyle) |
---|
469 | # ocidFormatterJP's setDateStyle:(current application's NSDateFormatterShortStyle) |
---|
470 | # ocidFormatterJP's setDateStyle:(current application's NSDateFormatterMediumStyle) |
---|
471 | # ocidFormatterJP's setDateStyle:(current application's NSDateFormatterLongStyle) |
---|
472 | ocidFormatterJP's setDateStyle:(current application's NSDateFormatterFullStyle) |
---|
473 | ###渡された値でフォーマット定義 |
---|
474 | ocidFormatterJP's setDateFormat:(strDateFormat) |
---|
475 | ###フォーマット適応 |
---|
476 | set ocidDateAndTime to ocidFormatterJP's stringFromDate:(ocidDate) |
---|
477 | ###テキストで戻す |
---|
478 | set strDateAndTime to ocidDateAndTime as text |
---|
479 | return strDateAndTime |
---|
480 | end doGetDateNo |
---|
481 | |
---|
482 | |
---|
483 | |
---|
484 | #################################### |
---|
485 | ###### HTML 生成 |
---|
486 | #################################### |
---|
487 | to doMakeHTML(argImageFileURL, argLinkURL) |
---|
488 | (* |
---|
489 | set ocidFilePathStr to refMe's NSString's stringWithString:(strFilePath) |
---|
490 | set ocidFilePath to ocidFilePathStr's stringByStandardizingPath() |
---|
491 | set ocidFilePathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidFilePath) isDirectory:false) |
---|
492 | *) |
---|
493 | ##保存先パス |
---|
494 | set strURL to argLinkURL as text |
---|
495 | set ocidFilePathURL to argImageFileURL |
---|
496 | set strFilePath to ocidFilePathURL's absoluteString() as text |
---|
497 | # |
---|
498 | set ocidContainerDirPathURL to ocidFilePathURL's URLByDeletingLastPathComponent() |
---|
499 | set ocidFileName to ocidFilePathURL's lastPathComponent() |
---|
500 | set ocidSaveFileName to ocidFileName's stringByAppendingPathExtension:("html") |
---|
501 | set ocidSaveFilePathURL to ocidContainerDirPathURL's URLByAppendingPathComponent:(ocidSaveFileName) |
---|
502 | |
---|
503 | ####################################### |
---|
504 | ##【1】 HTML 本体ROOT |
---|
505 | #XML初期化 |
---|
506 | set ocidXMLDoc to refMe's NSXMLDocument's alloc()'s init() |
---|
507 | ocidXMLDoc's setDocumentContentKind:(refMe's NSXMLDocumentHTMLKind) |
---|
508 | # DTD付与 |
---|
509 | set ocidDTD to refMe's NSXMLDTD's alloc()'s init() |
---|
510 | ocidDTD's setName:("html") |
---|
511 | ocidXMLDoc's setDTD:(ocidDTD) |
---|
512 | # |
---|
513 | set ocidRootElement to refMe's NSXMLElement's elementWithName:("html") |
---|
514 | set ocidAddNode to refMe's NSXMLNode's attributeWithName:("lang") stringValue:("ja") |
---|
515 | ocidRootElement's addAttribute:(ocidAddNode) |
---|
516 | |
---|
517 | ####################################### |
---|
518 | ##【2】head meta部分 |
---|
519 | set ocidHeadElement to refMe's NSXMLElement's elementWithName:("head") |
---|
520 | # |
---|
521 | set ocidAddElement to refMe's NSXMLElement's elementWithName:("title") |
---|
522 | ocidAddElement's setStringValue:("生成QRバーコード") |
---|
523 | ocidHeadElement's addChild:(ocidAddElement) |
---|
524 | # http-equiv |
---|
525 | set ocidAddElement to refMe's NSXMLElement's elementWithName:("meta") |
---|
526 | set ocidAddNode to refMe's NSXMLNode's attributeWithName:("http-equiv") stringValue:("Content-Type") |
---|
527 | ocidAddElement's addAttribute:(ocidAddNode) |
---|
528 | set ocidAddNode to refMe's NSXMLNode's attributeWithName:("content") stringValue:("text/html; charset=UTF-8") |
---|
529 | ocidAddElement's addAttribute:(ocidAddNode) |
---|
530 | ocidHeadElement's addChild:(ocidAddElement) |
---|
531 | # |
---|
532 | set ocidAddElement to refMe's NSXMLElement's elementWithName:("meta") |
---|
533 | set ocidAddNode to refMe's NSXMLNode's attributeWithName:("http-equiv") stringValue:("Content-Style-Type") |
---|
534 | ocidAddElement's addAttribute:(ocidAddNode) |
---|
535 | set ocidAddNode to refMe's NSXMLNode's attributeWithName:("content") stringValue:("text/css") |
---|
536 | ocidAddElement's addAttribute:(ocidAddNode) |
---|
537 | ocidHeadElement's addChild:(ocidAddElement) |
---|
538 | # |
---|
539 | set ocidAddElement to refMe's NSXMLElement's elementWithName:("meta") |
---|
540 | set ocidAddNode to refMe's NSXMLNode's attributeWithName:("http-equiv") stringValue:("Content-Script-Type") |
---|
541 | ocidAddElement's addAttribute:(ocidAddNode) |
---|
542 | set ocidAddNode to refMe's NSXMLNode's attributeWithName:("content") stringValue:("text/javascript") |
---|
543 | ocidAddElement's addAttribute:(ocidAddNode) |
---|
544 | ocidHeadElement's addChild:(ocidAddElement) |
---|
545 | # |
---|
546 | set ocidAddElement to refMe's NSXMLElement's elementWithName:("meta") |
---|
547 | set ocidAddNode to refMe's NSXMLNode's attributeWithName:("name") stringValue:("viewport") |
---|
548 | ocidAddElement's addAttribute:(ocidAddNode) |
---|
549 | set ocidAddNode to refMe's NSXMLNode's attributeWithName:("content") stringValue:("width=720") |
---|
550 | ocidAddElement's addAttribute:(ocidAddNode) |
---|
551 | ocidHeadElement's addChild:(ocidAddElement) |
---|
552 | # |
---|
553 | set ocidAddElement to refMe's NSXMLElement's elementWithName:("style") |
---|
554 | ocidAddElement's setStringValue:("body {margin: 10px;background-color: #FFFFFF;}header {width: 540px;border-color: #5c5c5c;border-style: solid;border-width: 1px;border-radius: 0.5cap;padding: 10px;margin: 10px;}article {width: 540px;padding: 20px;margin: 10px;}footer {width: 540px;}footer p {font-size: 8pt;}@font-face {font-family: 'OsakaMonoLocal';src: url('file:///System/Library/AssetsV2/com_apple_MobileAsset_Font7/0818d874bf1d0e24a1fe62e79f407717792c5ee1.asset/AssetData/OsakaMono.ttf') format('truetype');}p {font-family: OsakaMonoLocal;font-size: 14pt;}h3 {font-family: OsakaMonoLocal;font-size: 24pt;}.img_qr {max-width: 520px;}input {width: 480px;max-width: 520px;}") |
---|
555 | ocidHeadElement's addChild:(ocidAddElement) |
---|
556 | ocidRootElement's addChild:(ocidHeadElement) |
---|
557 | ######################################## |
---|
558 | ##【3】ボディ body |
---|
559 | set ocidBodyElement to refMe's NSXMLElement's elementWithName:("body") |
---|
560 | |
---|
561 | ######################################## |
---|
562 | ##【4】ヘッダー header |
---|
563 | set ocidHeaderElement to refMe's NSXMLElement's elementWithName:("header") |
---|
564 | set ocidAddNode to refMe's NSXMLNode's attributeWithName:("id") stringValue:("header") |
---|
565 | ocidHeaderElement's addAttribute:(ocidAddNode) |
---|
566 | set ocidAddNode to refMe's NSXMLNode's attributeWithName:("class") stringValue:("body_header") |
---|
567 | ocidHeaderElement's addAttribute:(ocidAddNode) |
---|
568 | # |
---|
569 | set ocidH3Element to refMe's NSXMLElement's elementWithName:("h3") |
---|
570 | set ocidAddNode to refMe's NSXMLNode's attributeWithName:("class") stringValue:("header_h3") |
---|
571 | ocidH3Element's addAttribute:(ocidAddNode) |
---|
572 | (ocidH3Element's setStringValue:("QRコード")) |
---|
573 | ocidHeaderElement's addChild:(ocidH3Element) |
---|
574 | # |
---|
575 | set ocidPElement to refMe's NSXMLElement's elementWithName:("p") |
---|
576 | set ocidAddNode to refMe's NSXMLNode's attributeWithName:("class") stringValue:("header_p") |
---|
577 | ocidPElement's addAttribute:(ocidAddNode) |
---|
578 | (ocidPElement's setStringValue:("QRコードの内容")) |
---|
579 | ocidHeaderElement's addChild:(ocidPElement) |
---|
580 | # |
---|
581 | #set ocidBrElement to refMe's NSXMLElement's elementWithName:("br") |
---|
582 | #ocidHeaderElement's addChild:(ocidBrElement) |
---|
583 | # |
---|
584 | set ocidPElement to refMe's NSXMLElement's elementWithName:("p") |
---|
585 | set ocidAddNode to refMe's NSXMLNode's attributeWithName:("class") stringValue:("header_p") |
---|
586 | ocidPElement's addAttribute:(ocidAddNode) |
---|
587 | # |
---|
588 | set ocidInputElement to refMe's NSXMLElement's elementWithName:("input") |
---|
589 | ocidInputElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("id") stringValue:("url")) |
---|
590 | ocidInputElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("type") stringValue:("url")) |
---|
591 | ocidInputElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("name") stringValue:("url")) |
---|
592 | ocidInputElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("placeholder") stringValue:(strURL)) |
---|
593 | ocidInputElement's addAttribute:(refMe's NSXMLNode's attributeWithName:("value") stringValue:(strURL)) |
---|
594 | ocidPElement's addChild:(ocidInputElement) |
---|
595 | ocidHeaderElement's addChild:(ocidPElement) |
---|
596 | # |
---|
597 | set ocidPElement to refMe's NSXMLElement's elementWithName:("p") |
---|
598 | set ocidAddNode to refMe's NSXMLNode's attributeWithName:("class") stringValue:("header_p") |
---|
599 | ocidPElement's addAttribute:(ocidAddNode) |
---|
600 | # |
---|
601 | set ocidAElement to refMe's NSXMLElement's elementWithName:("a") |
---|
602 | set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("href") stringValue:(strURL)) |
---|
603 | (ocidAElement's addAttribute:(ocidAddNode)) |
---|
604 | set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("target") stringValue:("_blank")) |
---|
605 | (ocidAElement's addAttribute:(ocidAddNode)) |
---|
606 | set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("class") stringValue:("header_a")) |
---|
607 | (ocidAElement's addAttribute:(ocidAddNode)) |
---|
608 | (ocidAElement's setStringValue:(strURL)) |
---|
609 | ocidPElement's addChild:(ocidAElement) |
---|
610 | ocidHeaderElement's addChild:(ocidPElement) |
---|
611 | # |
---|
612 | #set ocidHrElement to refMe's NSXMLElement's elementWithName:("hr") |
---|
613 | #ocidHeaderElement's addChild:(ocidHrElement) |
---|
614 | |
---|
615 | ####################################### |
---|
616 | ##【5】メインコンテンツ部 article |
---|
617 | set ocidArticleElement to refMe's NSXMLElement's elementWithName:("article") |
---|
618 | set ocidAddNode to refMe's NSXMLNode's attributeWithName:("id") stringValue:("article") |
---|
619 | ocidArticleElement's addAttribute:(ocidAddNode) |
---|
620 | set ocidAddNode to refMe's NSXMLNode's attributeWithName:("class") stringValue:("body_article") |
---|
621 | ocidArticleElement's addAttribute:(ocidAddNode) |
---|
622 | # |
---|
623 | set ocidDivElement to refMe's NSXMLElement's elementWithName:("div") |
---|
624 | set ocidAddNode to refMe's NSXMLNode's attributeWithName:("class") stringValue:("div_qr") |
---|
625 | ocidDivElement's addAttribute:(ocidAddNode) |
---|
626 | # |
---|
627 | set ocidAElement to refMe's NSXMLElement's elementWithName:("a") |
---|
628 | set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("href") stringValue:(strFilePath)) |
---|
629 | (ocidAElement's addAttribute:(ocidAddNode)) |
---|
630 | set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("target") stringValue:("_blank")) |
---|
631 | (ocidAElement's addAttribute:(ocidAddNode)) |
---|
632 | set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("class") stringValue:("a_qr")) |
---|
633 | (ocidAElement's addAttribute:(ocidAddNode)) |
---|
634 | # |
---|
635 | set ocidImgElement to refMe's NSXMLElement's elementWithName:("img") |
---|
636 | set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("src") stringValue:(strFilePath)) |
---|
637 | (ocidImgElement's addAttribute:(ocidAddNode)) |
---|
638 | set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("alt") stringValue:("生成したバーコードイメージ")) |
---|
639 | (ocidImgElement's addAttribute:(ocidAddNode)) |
---|
640 | set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("title") stringValue:("生成したバーコードイメージ")) |
---|
641 | (ocidImgElement's addAttribute:(ocidAddNode)) |
---|
642 | set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("class") stringValue:("img_qr")) |
---|
643 | (ocidImgElement's addAttribute:(ocidAddNode)) |
---|
644 | ocidAElement's addChild:(ocidImgElement) |
---|
645 | ocidDivElement's addChild:(ocidAElement) |
---|
646 | ocidArticleElement's addChild:(ocidDivElement) |
---|
647 | # |
---|
648 | #set ocidHrElement to refMe's NSXMLElement's elementWithName:("hr") |
---|
649 | #ocidArticleElement's addChild:(ocidHrElement) |
---|
650 | |
---|
651 | ######################################## |
---|
652 | ##【6】フッター footer |
---|
653 | set ocidFooterElement to refMe's NSXMLElement's elementWithName:("footer") |
---|
654 | set ocidAddNode to refMe's NSXMLNode's attributeWithName:("id") stringValue:("footer") |
---|
655 | ocidFooterElement's addAttribute:(ocidAddNode) |
---|
656 | set ocidAddNode to refMe's NSXMLNode's attributeWithName:("class") stringValue:("body_footer") |
---|
657 | ocidFooterElement's addAttribute:(ocidAddNode) |
---|
658 | # |
---|
659 | set ocidPElement to refMe's NSXMLElement's elementWithName:("p") |
---|
660 | set ocidAddNode to refMe's NSXMLNode's attributeWithName:("class") stringValue:("header_p") |
---|
661 | ocidPElement's addAttribute:(ocidAddNode) |
---|
662 | # |
---|
663 | set ocidAElement to refMe's NSXMLElement's elementWithName:("a") |
---|
664 | set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("href") stringValue:("https://quicktimer.cocolog-nifty.com/")) |
---|
665 | (ocidAElement's addAttribute:(ocidAddNode)) |
---|
666 | set ocidAddNode to (refMe's NSXMLNode's attributeWithName:("target") stringValue:("_blank")) |
---|
667 | (ocidAElement's addAttribute:(ocidAddNode)) |
---|
668 | set strContents to ("AppleScriptで生成しました") as text |
---|
669 | (ocidAElement's setStringValue:(strContents)) |
---|
670 | ocidPElement's addChild:(ocidAElement) |
---|
671 | |
---|
672 | ocidFooterElement's addChild:(ocidPElement) |
---|
673 | |
---|
674 | ######################################## |
---|
675 | ##【7】header article footerをbodyに追加 |
---|
676 | ocidBodyElement's addChild:(ocidHeaderElement) |
---|
677 | ocidBodyElement's addChild:(ocidArticleElement) |
---|
678 | ocidBodyElement's addChild:(ocidFooterElement) |
---|
679 | |
---|
680 | ######################################## |
---|
681 | ##【8】body をROOTに追加 |
---|
682 | ocidRootElement's addChild:(ocidBodyElement) |
---|
683 | |
---|
684 | ######################################## |
---|
685 | ##【9】ROOTをXMLセットしてXMLとしては完成 |
---|
686 | ocidXMLDoc's setRootElement:(ocidRootElement) |
---|
687 | |
---|
688 | ######################################## |
---|
689 | ##【10】保存 |
---|
690 | #読み取りやすい表示 データとして保存する |
---|
691 | set ocidXMLdata to ocidXMLDoc's XMLDataWithOptions:(refMe's NSXMLNodePrettyPrint) |
---|
692 | #保村 |
---|
693 | set listDone to ocidXMLdata's writeToURL:(ocidSaveFilePathURL) options:(refMe's NSDataWritingAtomic) |error| :(reference) |
---|
694 | if (item 2 of listDone) = (missing value) then |
---|
695 | log "保存しました" |
---|
696 | else if (item 1 of listDone) is false then |
---|
697 | log (item 2 of listDone)'s localizedFailureReason() as text |
---|
698 | return "保存に失敗しました" |
---|
699 | end if |
---|
700 | |
---|
701 | ######################################## |
---|
702 | ##【11】開く |
---|
703 | set aliasSaveFilePath to (ocidSaveFilePathURL's absoluteURL()) as alias |
---|
704 | tell application "Finder" |
---|
705 | open location aliasSaveFilePath |
---|
706 | end tell |
---|
707 | |
---|
708 | return true |
---|
709 | end doMakeHTML |
---|
710 | |
---|
711 | |
---|
712 | |
---|
713 | #################################### |
---|
714 | ###### %エンコード |
---|
715 | #################################### |
---|
716 | on doUrlEncode(argText) |
---|
717 | ##テキスト |
---|
718 | set ocidArgText to refMe's NSString's stringWithString:(argText) |
---|
719 | ##キャラクタセットを指定 |
---|
720 | set ocidChrSet to refMe's NSCharacterSet's URLQueryAllowedCharacterSet |
---|
721 | ##キャラクタセットで変換 |
---|
722 | set ocidArgTextEncoded to ocidArgText's stringByAddingPercentEncodingWithAllowedCharacters:(ocidChrSet) |
---|
723 | ######## 置換 %エンコードの追加処理 |
---|
724 | ###置換レコード |
---|
725 | set recordPercentMap to {|+|:"%2B", |=|:"%3D", |&|:"%26", |$|:"%24"} as record |
---|
726 | ###ディクショナリにして |
---|
727 | set ocidPercentMap to refMe's NSDictionary's alloc()'s initWithDictionary:(recordPercentMap) |
---|
728 | ###キーの一覧を取り出します |
---|
729 | set ocidAllKeys to ocidPercentMap's allKeys() |
---|
730 | ###取り出したキー一覧を順番に処理 |
---|
731 | repeat with itemAllKey in ocidAllKeys |
---|
732 | ##キーの値を取り出して |
---|
733 | set ocidMapValue to (ocidPercentMap's valueForKey:(itemAllKey)) |
---|
734 | ##置換 |
---|
735 | set ocidEncodedText to (ocidArgTextEncoded's stringByReplacingOccurrencesOfString:(itemAllKey) withString:(ocidMapValue)) |
---|
736 | ##次の変換に備える |
---|
737 | set ocidArgTextEncoded to ocidEncodedText |
---|
738 | end repeat |
---|
739 | ##テキスト形式に確定 |
---|
740 | set strTextToEncode to ocidEncodedText as text |
---|
741 | ###値を戻す |
---|
742 | return strTextToEncode |
---|
743 | end doUrlEncode |
---|