
複数画像の連結(マージ)横方向RTL 横方向LTR 縦方向TTBの3種類から選べるクイックアクション
ダウンロードはこちらから【Safari・FireFox用Script Editorで開く】 |
| ソース | |
|---|---|
| 001 | #!/usr/bin/env osascript |
| 002 | #coding: utf-8 |
| 003 | ----+----1----+----2----+-----3----+----4----+----5----+----6----+----7-- |
| 004 | (* |
| 005 | |
| 006 | 画像の合成 縦方向 横方向選択式のクイックアクション |
| 007 | |
| 008 | v1初回作成 |
| 009 | v1.1 右から左への起点の誤りを訂正 |
| 010 | |
| 011 | |
| 012 | |
| 013 | com.cocolog-nifty.quicktimer.icefloe *) |
| 014 | ----+----1----+----2----+-----3----+----4----+----5----+----6----+----7-- |
| 015 | use AppleScript version "2.8" |
| 016 | use framework "Foundation" |
| 017 | use framework "AppKit" |
| 018 | use framework "UniformTypeIdentifiers" |
| 019 | use scripting additions |
| 020 | |
| 021 | property refMe : a reference to current application |
| 022 | |
| 023 | ######################## |
| 024 | # RUN |
| 025 | |
| 026 | # on run {listAliasFilePath} |
| 027 | |
| 028 | (* |
| 029 | *) |
| 030 | on run |
| 031 | |
| 032 | set refResponse to doChooseFile() |
| 033 | if refResponse is false then |
| 034 | return false |
| 035 | else |
| 036 | set listAliasFilePath to refResponse as list |
| 037 | end if |
| 038 | |
| 039 | |
| 040 | set boolDone to (open listAliasFilePath) |
| 041 | return boolDone |
| 042 | end run |
| 043 | |
| 044 | ######################## |
| 045 | # OPEN |
| 046 | on open listAliasFilePath |
| 047 | ######## |
| 048 | set refResponse to doChooseList() |
| 049 | # 0"【左→右】横方向(L2R)" then |
| 050 | # 1 "【右→左】横方向(R2L)" |
| 051 | # 2 "【画像合成】縦方向" |
| 052 | |
| 053 | if refResponse = 0 then |
| 054 | set numDoMakeImage to refResponse as integer |
| 055 | else if refResponse = 1 then |
| 056 | set numDoMakeImage to refResponse as integer |
| 057 | else if refResponse = 2 then |
| 058 | set numDoMakeImage to refResponse as integer |
| 059 | |
| 060 | else if refResponse is false then |
| 061 | return false |
| 062 | end if |
| 063 | ######## |
| 064 | set listWhiteList to {"public.image", "public.png", "public.tiff", "public.jpeg", "org.webmproject.webp", "public.heic", "public.heif", "public.avci", "com.microsoft.bmp", "com.adobe.photoshop-image"} as list |
| 065 | set listImageFilePath to {} as list |
| 066 | repeat with itemAliasFilePath in listAliasFilePath |
| 067 | set aliasItemFilePath to itemAliasFilePath as alias |
| 068 | set recordInfoFor to (info for aliasItemFilePath) as record |
| 069 | set strUTI to (type identifier of recordInfoFor) as text |
| 070 | if listWhiteList contains strUTI then |
| 071 | set end of listImageFilePath to aliasItemFilePath |
| 072 | end if |
| 073 | end repeat |
| 074 | if listImageFilePath is not {} then |
| 075 | set boolDone to doMakeImage(listImageFilePath, numDoMakeImage) |
| 076 | end if |
| 077 | |
| 078 | |
| 079 | return boolDone |
| 080 | end open |
| 081 | |
| 082 | |
| 083 | ############################# |
| 084 | #本処理 |
| 085 | |
| 086 | on doMakeImage(listImageFilePath, numDoMakeImage) |
| 087 | #保存先 |
| 088 | set ocidSaveDirPathURL to doMakeSaveDir() |
| 089 | |
| 090 | #画像ピクセルサイズ |
| 091 | set listResponse to doGetImageSize(listImageFilePath) |
| 092 | set numMaxWpx to (first item of listResponse) as integer |
| 093 | set numMaxHpx to (second item of listResponse) as integer |
| 094 | set numTotalWpx to (third item of listResponse) as integer |
| 095 | set numTotalHpx to (last item of listResponse) as integer |
| 096 | # |
| 097 | set strDateNo to doGetDateNo("yyyyMMdd_HHmmss") as text |
| 098 | ############################# |
| 099 | #画像作成開始 |
| 100 | if numDoMakeImage = 0 then |
| 101 | #保存先 |
| 102 | set strSaveFileName to ("" & strDateNo & "-" & numTotalWpx & "x" & numMaxHpx & ".png") as text |
| 103 | set ocidSaveFilePathURL to ocidSaveDirPathURL's URLByAppendingPathComponent:(strSaveFileName) isDirectory:(false) |
| 104 | #処理開始 |
| 105 | set intBPR to (4 * numTotalWpx) as integer |
| 106 | set ocidAardboardRep to refMe's NSBitmapImageRep's alloc()'s initWithBitmapDataPlanes:(missing value) pixelsWide:(numTotalWpx) pixelsHigh:(numMaxHpx) bitsPerSample:(8) samplesPerPixel:(4) hasAlpha:(true) isPlanar:(false) colorSpaceName:(refMe's NSCalibratedRGBColorSpace) bitmapFormat:(refMe's NSAlphaFirstBitmapFormat) bytesPerRow:(intBPR) bitsPerPixel:(32) |
| 107 | #合成 |
| 108 | set numSetWpx to (missing value) |
| 109 | #▼▼▼saveGraphicsState |
| 110 | ###初期化 |
| 111 | refMe's NSGraphicsContext's saveGraphicsState() |
| 112 | set ocidContext to (refMe's NSGraphicsContext's graphicsContextWithBitmapImageRep:(ocidAardboardRep)) |
| 113 | (ocidContext's setShouldAntialias:(true)) |
| 114 | (ocidContext's setImageInterpolation:(refMe's NSImageInterpolationHigh)) |
| 115 | (ocidContext's setColorRenderingIntent:(refMe's NSColorRenderingIntentRelativeColorimetric)) |
| 116 | ocidContext's setPatternPhase:(refMe's NSPoint's NSMakePoint(0, 0)) |
| 117 | (refMe's NSGraphicsContext's setCurrentContext:(ocidContext)) |
| 118 | #ペースト処理 |
| 119 | repeat with itemAliasFilePath in listImageFilePath |
| 120 | #ファイル |
| 121 | set aliasFilePath to itemAliasFilePath as alias |
| 122 | set strFilePath to (POSIX path of aliasFilePath) as text |
| 123 | set ocidFilePathStr to (refMe's NSString's stringWithString:(strFilePath)) |
| 124 | set ocidFilePath to ocidFilePathStr's stringByStandardizingPath() |
| 125 | set ocidFilePathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidFilePath) isDirectory:(false)) |
| 126 | #NSDATA |
| 127 | set ocidOption to (refMe's NSDataReadingMappedIfSafe) |
| 128 | set listResponse to (refMe's NSData's alloc()'s initWithContentsOfURL:(ocidFilePathURL) options:(ocidOption) |error|:(reference)) |
| 129 | set ocidReadData to (first item of listResponse) |
| 130 | #NSIMAGE |
| 131 | set ocidReadImage to (refMe's NSImage's alloc()'s initWithData:(ocidReadData)) |
| 132 | #NSIMAGEREP |
| 133 | set ocidImageRepArray to ocidReadImage's representations() |
| 134 | set ocidImageRep to ocidImageRepArray's firstObject() |
| 135 | #ピクセルサイズ |
| 136 | set numPxW to ocidImageRep's pixelsWide() |
| 137 | set numPxH to ocidImageRep's pixelsHigh() |
| 138 | set ocidImageSizePx to refMe's NSSize's NSMakeSize(numPxW, numPxH) |
| 139 | (ocidImageRep's setSize:(ocidImageSizePx)) |
| 140 | set ocidFromRect to refMe's NSRect's NSMakeRect(0, 0, numPxW, numPxH) |
| 141 | #ペースト位置 |
| 142 | if numSetWpx = (missing value) then |
| 143 | set numSetWpx to 0 as integer |
| 144 | end if |
| 145 | set numSetHpx to (numMaxHpx - numPxH) as integer |
| 146 | set ocidDrawRect to refMe's NSRect's NSMakeRect(numSetWpx, numSetHpx, (numPxW), (numPxH)) |
| 147 | #元画像をペースト |
| 148 | set ocidOption to (refMe's NSCompositingOperationSourceOver) |
| 149 | (ocidImageRep's drawInRect:(ocidDrawRect) fromRect:(ocidFromRect) operation:(ocidOption) fraction:(1.0) respectFlipped:(true) hints:(missing value)) |
| 150 | #次の画像のペースト位置 |
| 151 | set numSetWpx to (numSetWpx + numPxW) as integer |
| 152 | #データは一旦解放 |
| 153 | set ocidImageRep to (missing value) |
| 154 | set ocidReadImage to (missing value) |
| 155 | set ocidReadData to (missing value) |
| 156 | end repeat |
| 157 | |
| 158 | ####画像作成終了 |
| 159 | refMe's NSGraphicsContext's restoreGraphicsState() |
| 160 | #▲▲▲ restoreGraphicsState |
| 161 | |
| 162 | |
| 163 | |
| 164 | |
| 165 | else if numDoMakeImage = 1 then |
| 166 | #保存先 |
| 167 | set strSaveFileName to ("" & strDateNo & "-" & numTotalWpx & "x" & numMaxHpx & ".png") as text |
| 168 | set ocidSaveFilePathURL to ocidSaveDirPathURL's URLByAppendingPathComponent:(strSaveFileName) isDirectory:(false) |
| 169 | #処理開始 |
| 170 | set intBPR to (4 * numTotalWpx) as integer |
| 171 | set ocidAardboardRep to refMe's NSBitmapImageRep's alloc()'s initWithBitmapDataPlanes:(missing value) pixelsWide:(numTotalWpx) pixelsHigh:(numMaxHpx) bitsPerSample:(8) samplesPerPixel:(4) hasAlpha:(true) isPlanar:(false) colorSpaceName:(refMe's NSCalibratedRGBColorSpace) bitmapFormat:(refMe's NSAlphaFirstBitmapFormat) bytesPerRow:(intBPR) bitsPerPixel:(32) |
| 172 | #合成 |
| 173 | set numSetWpx to (missing value) |
| 174 | #▼▼▼saveGraphicsState |
| 175 | ###初期化 |
| 176 | refMe's NSGraphicsContext's saveGraphicsState() |
| 177 | set ocidContext to (refMe's NSGraphicsContext's graphicsContextWithBitmapImageRep:(ocidAardboardRep)) |
| 178 | (ocidContext's setShouldAntialias:(true)) |
| 179 | (ocidContext's setImageInterpolation:(refMe's NSImageInterpolationHigh)) |
| 180 | (ocidContext's setColorRenderingIntent:(refMe's NSColorRenderingIntentRelativeColorimetric)) |
| 181 | ocidContext's setPatternPhase:(refMe's NSPoint's NSMakePoint(0, 0)) |
| 182 | (refMe's NSGraphicsContext's setCurrentContext:(ocidContext)) |
| 183 | #ペースト処理 |
| 184 | repeat with itemAliasFilePath in listImageFilePath |
| 185 | #ファイル |
| 186 | set aliasFilePath to itemAliasFilePath as alias |
| 187 | set strFilePath to (POSIX path of aliasFilePath) as text |
| 188 | set ocidFilePathStr to (refMe's NSString's stringWithString:(strFilePath)) |
| 189 | set ocidFilePath to ocidFilePathStr's stringByStandardizingPath() |
| 190 | set ocidFilePathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidFilePath) isDirectory:(false)) |
| 191 | #NSDATA |
| 192 | set ocidOption to (refMe's NSDataReadingMappedIfSafe) |
| 193 | set listResponse to (refMe's NSData's alloc()'s initWithContentsOfURL:(ocidFilePathURL) options:(ocidOption) |error|:(reference)) |
| 194 | set ocidReadData to (first item of listResponse) |
| 195 | #NSIMAGE |
| 196 | set ocidReadImage to (refMe's NSImage's alloc()'s initWithData:(ocidReadData)) |
| 197 | #NSIMAGEREP |
| 198 | set ocidImageRepArray to ocidReadImage's representations() |
| 199 | set ocidImageRep to ocidImageRepArray's firstObject() |
| 200 | #ピクセルサイズ |
| 201 | set numPxW to ocidImageRep's pixelsWide() |
| 202 | set numPxH to ocidImageRep's pixelsHigh() |
| 203 | set ocidImageSizePx to refMe's NSSize's NSMakeSize(numPxW, numPxH) |
| 204 | (ocidImageRep's setSize:(ocidImageSizePx)) |
| 205 | set ocidFromRect to refMe's NSRect's NSMakeRect(0, 0, numPxW, numPxH) |
| 206 | #ペースト位置 |
| 207 | #ペースト位置 |
| 208 | if numSetWpx = (missing value) then |
| 209 | set numSetWpx to (numTotalWpx - numPxW) as integer |
| 210 | else |
| 211 | set numSetWpx to (numTotalWpx - numPxW) as integer |
| 212 | end if |
| 213 | set numTotalWpx to numSetWpx as integer |
| 214 | set numSetHpx to (numMaxHpx - numPxH) as integer |
| 215 | set ocidDrawRect to refMe's NSRect's NSMakeRect(numSetWpx, numSetHpx, (numPxW), (numPxH)) |
| 216 | #元画像をペースト |
| 217 | set ocidOption to (refMe's NSCompositingOperationSourceOver) |
| 218 | (ocidImageRep's drawInRect:(ocidDrawRect) fromRect:(ocidFromRect) operation:(ocidOption) fraction:(1.0) respectFlipped:(true) hints:(missing value)) |
| 219 | #次の画像のペースト位置 |
| 220 | set numSetWpx to (numSetWpx - numPxW) as integer |
| 221 | #データは一旦解放 |
| 222 | set ocidImageRep to (missing value) |
| 223 | set ocidReadImage to (missing value) |
| 224 | set ocidReadData to (missing value) |
| 225 | end repeat |
| 226 | |
| 227 | ####画像作成終了 |
| 228 | refMe's NSGraphicsContext's restoreGraphicsState() |
| 229 | #▲▲▲ restoreGraphicsState |
| 230 | |
| 231 | |
| 232 | else if numDoMakeImage = 2 then |
| 233 | #保存先 |
| 234 | set strSaveFileName to ("" & strDateNo & "-" & numMaxWpx & "x" & numTotalHpx & ".png") as text |
| 235 | set ocidSaveFilePathURL to ocidSaveDirPathURL's URLByAppendingPathComponent:(strSaveFileName) isDirectory:(false) |
| 236 | #画像作成開始 |
| 237 | set intBPR to (4 * numMaxWpx) as integer |
| 238 | set ocidAardboardRep to refMe's NSBitmapImageRep's alloc()'s initWithBitmapDataPlanes:(missing value) pixelsWide:(numMaxWpx) pixelsHigh:(numTotalHpx) bitsPerSample:(8) samplesPerPixel:(4) hasAlpha:(true) isPlanar:(false) colorSpaceName:(refMe's NSCalibratedRGBColorSpace) bitmapFormat:(refMe's NSAlphaFirstBitmapFormat) bytesPerRow:(intBPR) bitsPerPixel:(32) |
| 239 | #合成 |
| 240 | set numSetHpx to (missing value) |
| 241 | #▼▼▼saveGraphicsState |
| 242 | ###初期化 |
| 243 | refMe's NSGraphicsContext's saveGraphicsState() |
| 244 | set ocidContext to (refMe's NSGraphicsContext's graphicsContextWithBitmapImageRep:(ocidAardboardRep)) |
| 245 | (ocidContext's setShouldAntialias:(true)) |
| 246 | (ocidContext's setImageInterpolation:(refMe's NSImageInterpolationHigh)) |
| 247 | (ocidContext's setColorRenderingIntent:(refMe's NSColorRenderingIntentRelativeColorimetric)) |
| 248 | ocidContext's setPatternPhase:(refMe's NSPoint's NSMakePoint(0, 0)) |
| 249 | (refMe's NSGraphicsContext's setCurrentContext:(ocidContext)) |
| 250 | #ペースト処理 |
| 251 | repeat with itemAliasFilePath in listImageFilePath |
| 252 | #ファイル |
| 253 | set aliasFilePath to itemAliasFilePath as alias |
| 254 | set strFilePath to (POSIX path of aliasFilePath) as text |
| 255 | set ocidFilePathStr to (refMe's NSString's stringWithString:(strFilePath)) |
| 256 | set ocidFilePath to ocidFilePathStr's stringByStandardizingPath() |
| 257 | set ocidFilePathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidFilePath) isDirectory:(false)) |
| 258 | #NSDATA |
| 259 | set ocidOption to (refMe's NSDataReadingMappedIfSafe) |
| 260 | set listResponse to (refMe's NSData's alloc()'s initWithContentsOfURL:(ocidFilePathURL) options:(ocidOption) |error|:(reference)) |
| 261 | set ocidReadData to (first item of listResponse) |
| 262 | #NSIMAGE |
| 263 | set ocidReadImage to (refMe's NSImage's alloc()'s initWithData:(ocidReadData)) |
| 264 | #NSIMAGEREP |
| 265 | set ocidImageRepArray to ocidReadImage's representations() |
| 266 | set ocidImageRep to ocidImageRepArray's firstObject() |
| 267 | #ピクセルサイズ |
| 268 | set numPxW to ocidImageRep's pixelsWide() |
| 269 | set numPxH to ocidImageRep's pixelsHigh() |
| 270 | set ocidImageSizePx to refMe's NSSize's NSMakeSize(numPxW, numPxH) |
| 271 | (ocidImageRep's setSize:(ocidImageSizePx)) |
| 272 | set ocidFromRect to refMe's NSRect's NSMakeRect(0, 0, numPxW, numPxH) |
| 273 | #ペースト位置 |
| 274 | set numSetHpx to (numTotalHpx - numPxH) as integer |
| 275 | set numSetWpx to (numMaxWpx - numPxW) as integer |
| 276 | set ocidDrawRect to refMe's NSRect's NSMakeRect(0, numSetHpx, (numPxW), (numPxH)) |
| 277 | # set ocidDrawRect to refMe's NSRect's NSMakeRect(numSetWpx, numSetHpx, (numPxW), (numPxH)) |
| 278 | #元画像をペースト |
| 279 | set ocidOption to (refMe's NSCompositingOperationSourceOver) |
| 280 | (ocidImageRep's drawInRect:(ocidDrawRect) fromRect:(ocidFromRect) operation:(ocidOption) fraction:(1.0) respectFlipped:(true) hints:(missing value)) |
| 281 | #次の画像のペースト位置 |
| 282 | set numTotalHpx to (numSetHpx) as integer |
| 283 | #データは一旦解放 |
| 284 | set ocidImageRep to (missing value) |
| 285 | set ocidReadImage to (missing value) |
| 286 | set ocidReadData to (missing value) |
| 287 | end repeat |
| 288 | |
| 289 | ####画像作成終了 |
| 290 | refMe's NSGraphicsContext's restoreGraphicsState() |
| 291 | #▲▲▲ restoreGraphicsState |
| 292 | |
| 293 | end if |
| 294 | |
| 295 | |
| 296 | #PNG変換 |
| 297 | set ocidProperty to refMe's NSMutableDictionary's alloc()'s init() |
| 298 | ocidProperty's setObject:(false) forKey:(refMe's NSImageInterlaced) |
| 299 | ocidProperty's setObject:(2.2) forKey:(refMe's NSImageGamma) |
| 300 | set ocidType to (refMe's NSBitmapImageFileTypePNG) |
| 301 | set ocidSaveData to (ocidAardboardRep's representationUsingType:(ocidType) |properties|:(ocidProperty)) |
| 302 | |
| 303 | #保存 |
| 304 | set ocidOption to (refMe's NSDataWritingAtomic) |
| 305 | set listDone to ocidSaveData's writeToURL:(ocidSaveFilePathURL) options:(ocidOption) |error|:(reference) |
| 306 | |
| 307 | #保存先を開く |
| 308 | set appSharedWorkspace to refMe's NSWorkspace's sharedWorkspace() |
| 309 | set boolDone to appSharedWorkspace's openURL:(ocidSaveDirPathURL) |
| 310 | |
| 311 | |
| 312 | return boolDone |
| 313 | end doMakeImage |
| 314 | |
| 315 | |
| 316 | ######################## |
| 317 | # 画像サイズ取得 |
| 318 | to doGetImageSize(listImageFilePath) |
| 319 | set numMaxWpx to 0 as integer |
| 320 | set numMaxHpx to 0 as integer |
| 321 | set numTotalWpx to 0 as integer |
| 322 | set numTotalHpx to 0 as integer |
| 323 | # |
| 324 | repeat with itemImageFilePath in listImageFilePath |
| 325 | set aliasFilePath to itemImageFilePath as alias |
| 326 | set strFilePath to (POSIX path of aliasFilePath) as text |
| 327 | set ocidFilePathStr to (refMe's NSString's stringWithString:(strFilePath)) |
| 328 | set ocidFilePath to ocidFilePathStr's stringByStandardizingPath() |
| 329 | set ocidFilePathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidFilePath) isDirectory:(false)) |
| 330 | #ピクセルサイズ |
| 331 | set ocidImageRep to (refMe's NSImageRep's imageRepWithContentsOfURL:(ocidFilePathURL)) |
| 332 | set numWpx to ocidImageRep's pixelsWide() |
| 333 | set numHpx to ocidImageRep's pixelsHigh() |
| 334 | |
| 335 | #最大ピクセルサイズ取得 |
| 336 | if numMaxWpx < numWpx then |
| 337 | set numMaxWpx to numWpx as integer |
| 338 | end if |
| 339 | if numMaxHpx < numHpx then |
| 340 | set numMaxHpx to numHpx as integer |
| 341 | end if |
| 342 | #合計ピクセルサイズ取得 |
| 343 | set numTotalWpx to (numTotalWpx + numWpx) as integer |
| 344 | set numTotalHpx to (numTotalHpx + numHpx) as integer |
| 345 | end repeat |
| 346 | set listResponse to {numMaxWpx, numMaxHpx, numTotalWpx, numTotalHpx} as list |
| 347 | return listResponse |
| 348 | end doGetImageSize |
| 349 | |
| 350 | |
| 351 | ######################## |
| 352 | #保存先確保 |
| 353 | to doMakeSaveDir() |
| 354 | set appFileManager to refMe's NSFileManager's defaultManager() |
| 355 | #出力画像保存先 |
| 356 | set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSPicturesDirectory) inDomains:(refMe's NSUserDomainMask)) |
| 357 | set ocidPicturesDirPathURL to ocidURLsArray's firstObject() |
| 358 | set ocidSaveDirPathURL to ocidPicturesDirPathURL's URLByAppendingPathComponent:("Image_Output") isDirectory:(true) |
| 359 | set ocidSaveDirPath to ocidSaveDirPathURL's |path|() |
| 360 | set boolExists to appFileManager's fileExistsAtPath:(ocidSaveDirPath) isDirectory:(true) |
| 361 | if boolExists is false then |
| 362 | #フォルダ作っておく |
| 363 | set ocidAttrDict to refMe's NSMutableDictionary's alloc()'s init() |
| 364 | ocidAttrDict's setValue:(448) forKey:(refMe's NSFilePosixPermissions) |
| 365 | set listDone to appFileManager's createDirectoryAtURL:(ocidSaveDirPathURL) withIntermediateDirectories:(true) attributes:(ocidAttrDict) |error|:(reference) |
| 366 | end if |
| 367 | return ocidSaveDirPathURL |
| 368 | end doMakeSaveDir |
| 369 | |
| 370 | |
| 371 | ######################## |
| 372 | #ダイアログ |
| 373 | to doChooseFile() |
| 374 | set strMsg to ("XXXXXX 選択") as text |
| 375 | set strPrompt to ("XXXXXX を選択してください" & return & "複数選択可") as text |
| 376 | set aliasDesktopDirPath to (path to desktop from user domain) as alias |
| 377 | set listUTI to {"public.item"} as list |
| 378 | try |
| 379 | tell application "SystemUIServer" |
| 380 | activate |
| 381 | set listAliasFilePath to (choose file strMsg with prompt strPrompt default location aliasDesktopDirPath of type listUTI with invisibles and multiple selections allowed without showing package contents) as list |
| 382 | end tell |
| 383 | on error strErrMes number numErrNo |
| 384 | log strErrMes & numErrNo |
| 385 | return false |
| 386 | end try |
| 387 | if listAliasFilePath is {} then |
| 388 | return false |
| 389 | end if |
| 390 | return listAliasFilePath |
| 391 | end doChooseFile |
| 392 | |
| 393 | ############################# |
| 394 | #ダイアログ |
| 395 | on doChooseList() |
| 396 | |
| 397 | set listJobs to {"【左→右】横方向(L2R)", "【右→左】横方向(R2L)", "【画像合成】縦方向"} as list |
| 398 | set strTitle to ("選んでください") as text |
| 399 | set strPrompt to ("ひとつ選んでください") as text |
| 400 | set strOK to ("OK") as text |
| 401 | set strCancel to ("キャンセル") as text |
| 402 | try |
| 403 | tell application "System Events" |
| 404 | activate |
| 405 | set valueResponse to (choose from list listJobs with title strTitle with prompt strPrompt default items (last item of listJobs) OK button name strOK cancel button name strCancel with empty selection allowed without multiple selections allowed) |
| 406 | end tell |
| 407 | on error strErrMes number numErrNo |
| 408 | log strErrMes & numErrNo |
| 409 | return false |
| 410 | end try |
| 411 | if (class of valueResponse) is boolean then |
| 412 | error "ユーザによってキャンセルされました。" number -128 |
| 413 | else if (class of valueResponse) is list then |
| 414 | if valueResponse is {} then |
| 415 | error "Error 何も選んでいません" number -128 |
| 416 | else |
| 417 | set strResponse to (first item of valueResponse) as text |
| 418 | end if |
| 419 | end if |
| 420 | ######### |
| 421 | |
| 422 | if strResponse is "【左→右】横方向(L2R)" then |
| 423 | return 0 |
| 424 | else if strResponse is "【右→左】横方向(R2L)" then |
| 425 | return 1 |
| 426 | else if strResponse is "【画像合成】縦方向" then |
| 427 | return 2 |
| 428 | else |
| 429 | return false |
| 430 | end if |
| 431 | |
| 432 | end doChooseList |
| 433 | |
| 434 | |
| 435 | ############################# |
| 436 | #日付情報の取得 |
| 437 | to doGetDateNo(argFormatStrings) |
| 438 | set ocidDate to refMe's NSDate's |date|() |
| 439 | set ocidNSDateFormatter to refMe's NSDateFormatter's alloc()'s init() |
| 440 | ocidNSDateFormatter's setLocale:(refMe's NSLocale's localeWithLocaleIdentifier:"ja_JP_POSIX") |
| 441 | ocidNSDateFormatter's setDateFormat:(argFormatStrings) |
| 442 | set ocidDateAndTime to ocidNSDateFormatter's stringFromDate:(ocidDate) |
| 443 | set strDateAndTime to ocidDateAndTime as text |
| 444 | return strDateAndTime |
| 445 | end doGetDateNo |
| AppleScriptで生成しました | |
| ソース | |
|---|---|
| 001 | #!/usr/bin/env osascript |
| 002 | #coding: utf-8 |
| 003 | ----+----1----+----2----+-----3----+----4----+----5----+----6----+----7-- |
| 004 | (* |
| 005 | |
| 006 | 画像の合成 縦方向 横方向選択式のクイックアクション |
| 007 | |
| 008 | v1初回作成 |
| 009 | |
| 010 | |
| 011 | com.cocolog-nifty.quicktimer.icefloe *) |
| 012 | ----+----1----+----2----+-----3----+----4----+----5----+----6----+----7-- |
| 013 | use AppleScript version "2.8" |
| 014 | use framework "Foundation" |
| 015 | use framework "AppKit" |
| 016 | use framework "UniformTypeIdentifiers" |
| 017 | use scripting additions |
| 018 | |
| 019 | property refMe : a reference to current application |
| 020 | |
| 021 | ######################## |
| 022 | # RUN |
| 023 | |
| 024 | on run {listAliasFilePath} |
| 025 | |
| 026 | (* |
| 027 | on run |
| 028 | |
| 029 | set refResponse to doChooseFile() |
| 030 | if refResponse is false then |
| 031 | return false |
| 032 | else |
| 033 | set listAliasFilePath to refResponse as list |
| 034 | end if |
| 035 | *) |
| 036 | |
| 037 | set boolDone to (open listAliasFilePath) |
| 038 | return boolDone |
| 039 | end run |
| 040 | |
| 041 | ######################## |
| 042 | # OPEN |
| 043 | on open listAliasFilePath |
| 044 | ######## |
| 045 | set refResponse to doChooseList() |
| 046 | if refResponse = 0 then |
| 047 | set numDoMakeImage to refResponse as integer |
| 048 | else if refResponse = 1 then |
| 049 | set numDoMakeImage to refResponse as integer |
| 050 | else if refResponse = 2 then |
| 051 | set numDoMakeImage to refResponse as integer |
| 052 | |
| 053 | else if refResponse is false then |
| 054 | return false |
| 055 | end if |
| 056 | ######## |
| 057 | set listWhiteList to {"public.image", "public.png", "public.tiff", "public.jpeg", "org.webmproject.webp", "public.heic", "public.heif", "public.avci", "com.microsoft.bmp", "com.adobe.photoshop-image"} as list |
| 058 | set listImageFilePath to {} as list |
| 059 | repeat with itemAliasFilePath in listAliasFilePath |
| 060 | set aliasItemFilePath to itemAliasFilePath as alias |
| 061 | set recordInfoFor to (info for aliasItemFilePath) as record |
| 062 | set strUTI to (type identifier of recordInfoFor) as text |
| 063 | if listWhiteList contains strUTI then |
| 064 | set end of listImageFilePath to aliasItemFilePath |
| 065 | end if |
| 066 | end repeat |
| 067 | if listImageFilePath is not {} then |
| 068 | set boolDone to doMakeImage(listImageFilePath, numDoMakeImage) |
| 069 | end if |
| 070 | |
| 071 | |
| 072 | return boolDone |
| 073 | end open |
| 074 | |
| 075 | |
| 076 | ############################# |
| 077 | #本処理 |
| 078 | |
| 079 | on doMakeImage(listImageFilePath, numDoMakeImage) |
| 080 | #保存先 |
| 081 | set ocidSaveDirPathURL to doMakeSaveDir() |
| 082 | |
| 083 | #画像ピクセルサイズ |
| 084 | set listResponse to doGetImageSize(listImageFilePath) |
| 085 | set numMaxWpx to (first item of listResponse) as integer |
| 086 | set numMaxHpx to (second item of listResponse) as integer |
| 087 | set numTotalWpx to (third item of listResponse) as integer |
| 088 | set numTotalHpx to (last item of listResponse) as integer |
| 089 | # |
| 090 | set strDateNo to doGetDateNo("yyyyMMdd_HHmmss") as text |
| 091 | ############################# |
| 092 | #画像作成開始 |
| 093 | if numDoMakeImage = 0 then |
| 094 | #保存先 |
| 095 | set strSaveFileName to ("" & strDateNo & "-" & numTotalWpx & "x" & numMaxHpx & ".png") as text |
| 096 | set ocidSaveFilePathURL to ocidSaveDirPathURL's URLByAppendingPathComponent:(strSaveFileName) isDirectory:(false) |
| 097 | #処理開始 |
| 098 | set intBPR to (4 * numTotalWpx) as integer |
| 099 | set ocidAardboardRep to refMe's NSBitmapImageRep's alloc()'s initWithBitmapDataPlanes:(missing value) pixelsWide:(numTotalWpx) pixelsHigh:(numMaxHpx) bitsPerSample:(8) samplesPerPixel:(4) hasAlpha:(true) isPlanar:(false) colorSpaceName:(refMe's NSCalibratedRGBColorSpace) bitmapFormat:(refMe's NSAlphaFirstBitmapFormat) bytesPerRow:(intBPR) bitsPerPixel:(32) |
| 100 | #合成 |
| 101 | set numSetWpx to (missing value) |
| 102 | #▼▼▼saveGraphicsState |
| 103 | ###初期化 |
| 104 | refMe's NSGraphicsContext's saveGraphicsState() |
| 105 | set ocidContext to (refMe's NSGraphicsContext's graphicsContextWithBitmapImageRep:(ocidAardboardRep)) |
| 106 | (ocidContext's setShouldAntialias:(true)) |
| 107 | (ocidContext's setImageInterpolation:(refMe's NSImageInterpolationHigh)) |
| 108 | (ocidContext's setColorRenderingIntent:(refMe's NSColorRenderingIntentRelativeColorimetric)) |
| 109 | ocidContext's setPatternPhase:(refMe's NSPoint's NSMakePoint(0, 0)) |
| 110 | (refMe's NSGraphicsContext's setCurrentContext:(ocidContext)) |
| 111 | #ペースト処理 |
| 112 | repeat with itemAliasFilePath in listImageFilePath |
| 113 | #ファイル |
| 114 | set aliasFilePath to itemAliasFilePath as alias |
| 115 | set strFilePath to (POSIX path of aliasFilePath) as text |
| 116 | set ocidFilePathStr to (refMe's NSString's stringWithString:(strFilePath)) |
| 117 | set ocidFilePath to ocidFilePathStr's stringByStandardizingPath() |
| 118 | set ocidFilePathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidFilePath) isDirectory:(false)) |
| 119 | #NSDATA |
| 120 | set ocidOption to (refMe's NSDataReadingMappedIfSafe) |
| 121 | set listResponse to (refMe's NSData's alloc()'s initWithContentsOfURL:(ocidFilePathURL) options:(ocidOption) |error|:(reference)) |
| 122 | set ocidReadData to (first item of listResponse) |
| 123 | #NSIMAGE |
| 124 | set ocidReadImage to (refMe's NSImage's alloc()'s initWithData:(ocidReadData)) |
| 125 | #NSIMAGEREP |
| 126 | set ocidImageRepArray to ocidReadImage's representations() |
| 127 | set ocidImageRep to ocidImageRepArray's firstObject() |
| 128 | #ピクセルサイズ |
| 129 | set numPxW to ocidImageRep's pixelsWide() |
| 130 | set numPxH to ocidImageRep's pixelsHigh() |
| 131 | set ocidImageSizePx to refMe's NSSize's NSMakeSize(numPxW, numPxH) |
| 132 | (ocidImageRep's setSize:(ocidImageSizePx)) |
| 133 | set ocidFromRect to refMe's NSRect's NSMakeRect(0, 0, numPxW, numPxH) |
| 134 | #ペースト位置 |
| 135 | if numSetWpx = (missing value) then |
| 136 | set numSetWpx to 0 as integer |
| 137 | end if |
| 138 | set numSetHpx to (numMaxHpx - numPxH) as integer |
| 139 | set ocidDrawRect to refMe's NSRect's NSMakeRect(numSetWpx, numSetHpx, (numPxW), (numPxH)) |
| 140 | #元画像をペースト |
| 141 | set ocidOption to (refMe's NSCompositingOperationSourceOver) |
| 142 | (ocidImageRep's drawInRect:(ocidDrawRect) fromRect:(ocidFromRect) operation:(ocidOption) fraction:(1.0) respectFlipped:(true) hints:(missing value)) |
| 143 | #次の画像のペースト位置 |
| 144 | set numSetWpx to (numSetWpx + numPxW) as integer |
| 145 | #データは一旦解放 |
| 146 | set ocidImageRep to (missing value) |
| 147 | set ocidReadImage to (missing value) |
| 148 | set ocidReadData to (missing value) |
| 149 | end repeat |
| 150 | |
| 151 | ####画像作成終了 |
| 152 | refMe's NSGraphicsContext's restoreGraphicsState() |
| 153 | #▲▲▲ restoreGraphicsState |
| 154 | |
| 155 | |
| 156 | |
| 157 | |
| 158 | else if numDoMakeImage = 2 then |
| 159 | #保存先 |
| 160 | set strSaveFileName to ("" & strDateNo & "-" & numTotalWpx & "x" & numMaxHpx & ".png") as text |
| 161 | set ocidSaveFilePathURL to ocidSaveDirPathURL's URLByAppendingPathComponent:(strSaveFileName) isDirectory:(false) |
| 162 | #処理開始 |
| 163 | set intBPR to (4 * numTotalWpx) as integer |
| 164 | set ocidAardboardRep to refMe's NSBitmapImageRep's alloc()'s initWithBitmapDataPlanes:(missing value) pixelsWide:(numTotalWpx) pixelsHigh:(numMaxHpx) bitsPerSample:(8) samplesPerPixel:(4) hasAlpha:(true) isPlanar:(false) colorSpaceName:(refMe's NSCalibratedRGBColorSpace) bitmapFormat:(refMe's NSAlphaFirstBitmapFormat) bytesPerRow:(intBPR) bitsPerPixel:(32) |
| 165 | #合成 |
| 166 | set numSetWpx to (missing value) |
| 167 | #▼▼▼saveGraphicsState |
| 168 | ###初期化 |
| 169 | refMe's NSGraphicsContext's saveGraphicsState() |
| 170 | set ocidContext to (refMe's NSGraphicsContext's graphicsContextWithBitmapImageRep:(ocidAardboardRep)) |
| 171 | (ocidContext's setShouldAntialias:(true)) |
| 172 | (ocidContext's setImageInterpolation:(refMe's NSImageInterpolationHigh)) |
| 173 | (ocidContext's setColorRenderingIntent:(refMe's NSColorRenderingIntentRelativeColorimetric)) |
| 174 | ocidContext's setPatternPhase:(refMe's NSPoint's NSMakePoint(0, 0)) |
| 175 | (refMe's NSGraphicsContext's setCurrentContext:(ocidContext)) |
| 176 | #ペースト処理 |
| 177 | repeat with itemAliasFilePath in listImageFilePath |
| 178 | #ファイル |
| 179 | set aliasFilePath to itemAliasFilePath as alias |
| 180 | set strFilePath to (POSIX path of aliasFilePath) as text |
| 181 | set ocidFilePathStr to (refMe's NSString's stringWithString:(strFilePath)) |
| 182 | set ocidFilePath to ocidFilePathStr's stringByStandardizingPath() |
| 183 | set ocidFilePathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidFilePath) isDirectory:(false)) |
| 184 | #NSDATA |
| 185 | set ocidOption to (refMe's NSDataReadingMappedIfSafe) |
| 186 | set listResponse to (refMe's NSData's alloc()'s initWithContentsOfURL:(ocidFilePathURL) options:(ocidOption) |error|:(reference)) |
| 187 | set ocidReadData to (first item of listResponse) |
| 188 | #NSIMAGE |
| 189 | set ocidReadImage to (refMe's NSImage's alloc()'s initWithData:(ocidReadData)) |
| 190 | #NSIMAGEREP |
| 191 | set ocidImageRepArray to ocidReadImage's representations() |
| 192 | set ocidImageRep to ocidImageRepArray's firstObject() |
| 193 | #ピクセルサイズ |
| 194 | set numPxW to ocidImageRep's pixelsWide() |
| 195 | set numPxH to ocidImageRep's pixelsHigh() |
| 196 | set ocidImageSizePx to refMe's NSSize's NSMakeSize(numPxW, numPxH) |
| 197 | (ocidImageRep's setSize:(ocidImageSizePx)) |
| 198 | set ocidFromRect to refMe's NSRect's NSMakeRect(0, 0, numPxW, numPxH) |
| 199 | #ペースト位置 |
| 200 | if numSetWpx = (missing value) then |
| 201 | set numSetWpx to (numTotalWpx - numPxW) as integer |
| 202 | end if |
| 203 | set numSetHpx to (numMaxHpx - numPxH) as integer |
| 204 | set ocidDrawRect to refMe's NSRect's NSMakeRect(numSetWpx, numSetHpx, (numPxW), (numPxH)) |
| 205 | #元画像をペースト |
| 206 | set ocidOption to (refMe's NSCompositingOperationSourceOver) |
| 207 | (ocidImageRep's drawInRect:(ocidDrawRect) fromRect:(ocidFromRect) operation:(ocidOption) fraction:(1.0) respectFlipped:(true) hints:(missing value)) |
| 208 | #次の画像のペースト位置 |
| 209 | set numSetWpx to (numSetWpx - numPxW) as integer |
| 210 | #データは一旦解放 |
| 211 | set ocidImageRep to (missing value) |
| 212 | set ocidReadImage to (missing value) |
| 213 | set ocidReadData to (missing value) |
| 214 | end repeat |
| 215 | |
| 216 | ####画像作成終了 |
| 217 | refMe's NSGraphicsContext's restoreGraphicsState() |
| 218 | #▲▲▲ restoreGraphicsState |
| 219 | |
| 220 | |
| 221 | |
| 222 | |
| 223 | |
| 224 | |
| 225 | else if numDoMakeImage = 1 then |
| 226 | #保存先 |
| 227 | set strSaveFileName to ("" & strDateNo & "-" & numMaxWpx & "x" & numTotalHpx & ".png") as text |
| 228 | set ocidSaveFilePathURL to ocidSaveDirPathURL's URLByAppendingPathComponent:(strSaveFileName) isDirectory:(false) |
| 229 | #画像作成開始 |
| 230 | set intBPR to (4 * numMaxWpx) as integer |
| 231 | set ocidAardboardRep to refMe's NSBitmapImageRep's alloc()'s initWithBitmapDataPlanes:(missing value) pixelsWide:(numMaxWpx) pixelsHigh:(numTotalHpx) bitsPerSample:(8) samplesPerPixel:(4) hasAlpha:(true) isPlanar:(false) colorSpaceName:(refMe's NSCalibratedRGBColorSpace) bitmapFormat:(refMe's NSAlphaFirstBitmapFormat) bytesPerRow:(intBPR) bitsPerPixel:(32) |
| 232 | #合成 |
| 233 | set numSetHpx to (missing value) |
| 234 | #▼▼▼saveGraphicsState |
| 235 | ###初期化 |
| 236 | refMe's NSGraphicsContext's saveGraphicsState() |
| 237 | set ocidContext to (refMe's NSGraphicsContext's graphicsContextWithBitmapImageRep:(ocidAardboardRep)) |
| 238 | (ocidContext's setShouldAntialias:(true)) |
| 239 | (ocidContext's setImageInterpolation:(refMe's NSImageInterpolationHigh)) |
| 240 | (ocidContext's setColorRenderingIntent:(refMe's NSColorRenderingIntentRelativeColorimetric)) |
| 241 | ocidContext's setPatternPhase:(refMe's NSPoint's NSMakePoint(0, 0)) |
| 242 | (refMe's NSGraphicsContext's setCurrentContext:(ocidContext)) |
| 243 | #ペースト処理 |
| 244 | repeat with itemAliasFilePath in listImageFilePath |
| 245 | #ファイル |
| 246 | set aliasFilePath to itemAliasFilePath as alias |
| 247 | set strFilePath to (POSIX path of aliasFilePath) as text |
| 248 | set ocidFilePathStr to (refMe's NSString's stringWithString:(strFilePath)) |
| 249 | set ocidFilePath to ocidFilePathStr's stringByStandardizingPath() |
| 250 | set ocidFilePathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidFilePath) isDirectory:(false)) |
| 251 | #NSDATA |
| 252 | set ocidOption to (refMe's NSDataReadingMappedIfSafe) |
| 253 | set listResponse to (refMe's NSData's alloc()'s initWithContentsOfURL:(ocidFilePathURL) options:(ocidOption) |error|:(reference)) |
| 254 | set ocidReadData to (first item of listResponse) |
| 255 | #NSIMAGE |
| 256 | set ocidReadImage to (refMe's NSImage's alloc()'s initWithData:(ocidReadData)) |
| 257 | #NSIMAGEREP |
| 258 | set ocidImageRepArray to ocidReadImage's representations() |
| 259 | set ocidImageRep to ocidImageRepArray's firstObject() |
| 260 | #ピクセルサイズ |
| 261 | set numPxW to ocidImageRep's pixelsWide() |
| 262 | set numPxH to ocidImageRep's pixelsHigh() |
| 263 | set ocidImageSizePx to refMe's NSSize's NSMakeSize(numPxW, numPxH) |
| 264 | (ocidImageRep's setSize:(ocidImageSizePx)) |
| 265 | set ocidFromRect to refMe's NSRect's NSMakeRect(0, 0, numPxW, numPxH) |
| 266 | #ペースト位置 |
| 267 | set numSetHpx to (numTotalHpx - numPxH) as integer |
| 268 | set numSetWpx to (numMaxWpx - numPxW) as integer |
| 269 | set ocidDrawRect to refMe's NSRect's NSMakeRect(0, numSetHpx, (numPxW), (numPxH)) |
| 270 | # set ocidDrawRect to refMe's NSRect's NSMakeRect(numSetWpx, numSetHpx, (numPxW), (numPxH)) |
| 271 | #元画像をペースト |
| 272 | set ocidOption to (refMe's NSCompositingOperationSourceOver) |
| 273 | (ocidImageRep's drawInRect:(ocidDrawRect) fromRect:(ocidFromRect) operation:(ocidOption) fraction:(1.0) respectFlipped:(true) hints:(missing value)) |
| 274 | #次の画像のペースト位置 |
| 275 | set numTotalHpx to (numSetHpx) as integer |
| 276 | #データは一旦解放 |
| 277 | set ocidImageRep to (missing value) |
| 278 | set ocidReadImage to (missing value) |
| 279 | set ocidReadData to (missing value) |
| 280 | end repeat |
| 281 | |
| 282 | ####画像作成終了 |
| 283 | refMe's NSGraphicsContext's restoreGraphicsState() |
| 284 | #▲▲▲ restoreGraphicsState |
| 285 | |
| 286 | end if |
| 287 | |
| 288 | |
| 289 | #PNG変換 |
| 290 | set ocidProperty to refMe's NSMutableDictionary's alloc()'s init() |
| 291 | ocidProperty's setObject:(false) forKey:(refMe's NSImageInterlaced) |
| 292 | ocidProperty's setObject:(2.2) forKey:(refMe's NSImageGamma) |
| 293 | set ocidType to (refMe's NSBitmapImageFileTypePNG) |
| 294 | set ocidSaveData to (ocidAardboardRep's representationUsingType:(ocidType) |properties|:(ocidProperty)) |
| 295 | |
| 296 | #保存 |
| 297 | set ocidOption to (refMe's NSDataWritingAtomic) |
| 298 | set listDone to ocidSaveData's writeToURL:(ocidSaveFilePathURL) options:(ocidOption) |error|:(reference) |
| 299 | |
| 300 | #保存先を開く |
| 301 | set appSharedWorkspace to refMe's NSWorkspace's sharedWorkspace() |
| 302 | set boolDone to appSharedWorkspace's openURL:(ocidSaveDirPathURL) |
| 303 | |
| 304 | |
| 305 | return boolDone |
| 306 | end doMakeImage |
| 307 | |
| 308 | |
| 309 | ######################## |
| 310 | # 画像サイズ取得 |
| 311 | to doGetImageSize(listImageFilePath) |
| 312 | set numMaxWpx to 0 as integer |
| 313 | set numMaxHpx to 0 as integer |
| 314 | set numTotalWpx to 0 as integer |
| 315 | set numTotalHpx to 0 as integer |
| 316 | # |
| 317 | repeat with itemImageFilePath in listImageFilePath |
| 318 | set aliasFilePath to itemImageFilePath as alias |
| 319 | set strFilePath to (POSIX path of aliasFilePath) as text |
| 320 | set ocidFilePathStr to (refMe's NSString's stringWithString:(strFilePath)) |
| 321 | set ocidFilePath to ocidFilePathStr's stringByStandardizingPath() |
| 322 | set ocidFilePathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidFilePath) isDirectory:(false)) |
| 323 | #ピクセルサイズ |
| 324 | set ocidImageRep to (refMe's NSImageRep's imageRepWithContentsOfURL:(ocidFilePathURL)) |
| 325 | set numWpx to ocidImageRep's pixelsWide() |
| 326 | set numHpx to ocidImageRep's pixelsHigh() |
| 327 | |
| 328 | #最大ピクセルサイズ取得 |
| 329 | if numMaxWpx < numWpx then |
| 330 | set numMaxWpx to numWpx as integer |
| 331 | end if |
| 332 | if numMaxHpx < numHpx then |
| 333 | set numMaxHpx to numHpx as integer |
| 334 | end if |
| 335 | #合計ピクセルサイズ取得 |
| 336 | set numTotalWpx to (numTotalWpx + numWpx) as integer |
| 337 | set numTotalHpx to (numTotalHpx + numHpx) as integer |
| 338 | end repeat |
| 339 | set listResponse to {numMaxWpx, numMaxHpx, numTotalWpx, numTotalHpx} as list |
| 340 | return listResponse |
| 341 | end doGetImageSize |
| 342 | |
| 343 | |
| 344 | ######################## |
| 345 | #保存先確保 |
| 346 | to doMakeSaveDir() |
| 347 | set appFileManager to refMe's NSFileManager's defaultManager() |
| 348 | #出力画像保存先 |
| 349 | set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSPicturesDirectory) inDomains:(refMe's NSUserDomainMask)) |
| 350 | set ocidPicturesDirPathURL to ocidURLsArray's firstObject() |
| 351 | set ocidSaveDirPathURL to ocidPicturesDirPathURL's URLByAppendingPathComponent:("Image_Output") isDirectory:(true) |
| 352 | set ocidSaveDirPath to ocidSaveDirPathURL's |path|() |
| 353 | set boolExists to appFileManager's fileExistsAtPath:(ocidSaveDirPath) isDirectory:(true) |
| 354 | if boolExists is false then |
| 355 | #フォルダ作っておく |
| 356 | set ocidAttrDict to refMe's NSMutableDictionary's alloc()'s init() |
| 357 | ocidAttrDict's setValue:(448) forKey:(refMe's NSFilePosixPermissions) |
| 358 | set listDone to appFileManager's createDirectoryAtURL:(ocidSaveDirPathURL) withIntermediateDirectories:(true) attributes:(ocidAttrDict) |error|:(reference) |
| 359 | end if |
| 360 | return ocidSaveDirPathURL |
| 361 | end doMakeSaveDir |
| 362 | |
| 363 | |
| 364 | ######################## |
| 365 | #ダイアログ |
| 366 | to doChooseFile() |
| 367 | set strMsg to ("XXXXXX 選択") as text |
| 368 | set strPrompt to ("XXXXXX を選択してください" & return & "複数選択可") as text |
| 369 | set aliasDesktopDirPath to (path to desktop from user domain) as alias |
| 370 | set listUTI to {"public.item"} as list |
| 371 | try |
| 372 | tell application "SystemUIServer" |
| 373 | activate |
| 374 | set listAliasFilePath to (choose file strMsg with prompt strPrompt default location aliasDesktopDirPath of type listUTI with invisibles and multiple selections allowed without showing package contents) as list |
| 375 | end tell |
| 376 | on error strErrMes number numErrNo |
| 377 | log strErrMes & numErrNo |
| 378 | return false |
| 379 | end try |
| 380 | if listAliasFilePath is {} then |
| 381 | return false |
| 382 | end if |
| 383 | return listAliasFilePath |
| 384 | end doChooseFile |
| 385 | |
| 386 | ############################# |
| 387 | #ダイアログ |
| 388 | on doChooseList() |
| 389 | |
| 390 | set listJobs to {"【左→右】横方向(L2R)", "【右→左】横方向(R2L)", "【画像合成】縦方向"} as list |
| 391 | set strTitle to ("選んでください") as text |
| 392 | set strPrompt to ("ひとつ選んでください") as text |
| 393 | set strOK to ("OK") as text |
| 394 | set strCancel to ("キャンセル") as text |
| 395 | try |
| 396 | tell application "System Events" |
| 397 | activate |
| 398 | set valueResponse to (choose from list listJobs with title strTitle with prompt strPrompt default items (last item of listJobs) OK button name strOK cancel button name strCancel with empty selection allowed without multiple selections allowed) |
| 399 | end tell |
| 400 | on error strErrMes number numErrNo |
| 401 | log strErrMes & numErrNo |
| 402 | return false |
| 403 | end try |
| 404 | if (class of valueResponse) is boolean then |
| 405 | error "ユーザによってキャンセルされました。" number -128 |
| 406 | else if (class of valueResponse) is list then |
| 407 | if valueResponse is {} then |
| 408 | error "Error 何も選んでいません" number -128 |
| 409 | else |
| 410 | set strResponse to (first item of valueResponse) as text |
| 411 | end if |
| 412 | end if |
| 413 | ######### |
| 414 | |
| 415 | if strResponse is "【左→右】横方向(L2R)" then |
| 416 | return 0 |
| 417 | else if strResponse is "【右→左】横方向(R2L)" then |
| 418 | return 2 |
| 419 | else if strResponse is "【画像合成】縦方向" then |
| 420 | return 1 |
| 421 | else |
| 422 | return false |
| 423 | end if |
| 424 | |
| 425 | end doChooseList |
| 426 | |
| 427 | |
| 428 | ############################# |
| 429 | #日付情報の取得 |
| 430 | to doGetDateNo(argFormatStrings) |
| 431 | set ocidDate to refMe's NSDate's |date|() |
| 432 | set ocidNSDateFormatter to refMe's NSDateFormatter's alloc()'s init() |
| 433 | ocidNSDateFormatter's setLocale:(refMe's NSLocale's localeWithLocaleIdentifier:"ja_JP_POSIX") |
| 434 | ocidNSDateFormatter's setDateFormat:(argFormatStrings) |
| 435 | set ocidDateAndTime to ocidNSDateFormatter's stringFromDate:(ocidDate) |
| 436 | set strDateAndTime to ocidDateAndTime as text |
| 437 | return strDateAndTime |
| 438 | end doGetDateNo |
| AppleScriptで生成しました | |
