20260614

OBJC記法 MakePDF フォルダ指定

OBJC記法 MakePDF フォルダ指定

NOTE記事一覧ですnote.com

【Safari・FireFox用Script Editorで開く】 |

[OBJC]Img2MakePDF.scpt.scpt
ソース
001#!/usr/bin/env osascript
002#coding: utf-8
003----+----1----+----2----+-----3----+----4----+----5----+----6----+----7--
004(*
005
006com.cocolog-nifty.quicktimer.icefloe *)
007----+----1----+----2----+-----3----+----4----+----5----+----6----+----7--
008use AppleScript version "2.8"
009use framework "Foundation"
010use framework "AppKit"
011use scripting additions
012
013########################
014# RUN
015on run
016   #{listAliasFilePath}
017   
018   
019   ########################
020   #Dialog
021   set strMsg to ("Choose file") as text
022   set strPrompt to ("Choose file" & return & "multiple selections allowed") as text
023   set aliasDesktopDirPath to (path to desktop from user domain) as alias
024   set listUTI to {"public.item"} as list
025   try
026      tell application "Finder"
027         #Finderから呼び出すことでスクリプトアプリケーションになってもダイアログがマルチリンガルになります
028         #By calling from Finder, the dialog becomes multilingual even if it becomes a script application.
029         tell application "SystemUIServer"
030            activate
031            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
032         end tell
033      end tell
034   on error strErrMes number numErrNo
035      log strErrMes & numErrNo
036      return false
037   end try
038   
039   
040   set boolDone to (open listAliasFilePath) as boolean
041   return boolDone
042end run
043
044########################
045# OPEN
046on open listAliasFilePath
047   
048   set listImgFilePath to {} as list
049   
050   set listImageUTI to {"public.image", "public.png", "public.tiff", "public.jpeg", "public.heic"} as list
051   
052   
053   repeat with itemAliasFilePath in listAliasFilePath
054      set aliasItemFilePath to itemAliasFilePath as alias
055      set recordInfoFor to (info for aliasItemFilePath) as record
056      set boolIsDir to (folder of recordInfoFor) as boolean
057      if boolIsDir is true then
058         set boolDone to doFolderJon(aliasItemFilePath) as boolean
059      else if boolIsDir is false then
060         set strUTI to (type identifier of recordInfoFor) as text
061         if listImageUTI contains strUTI then
062            set end of listImgFilePath to aliasItemFilePath
063         end if
064      end if
065      
066   end repeat
067   
068   
069   set boolDone to doOpenImg(listImgFilePath)
070   
071   return true
072end open
073
074
075########################
076#Do Folder JOB
077to doFolderJon(argAliasFilePath)
078   
079   return false
080end doFolderJon
081
082
083########################
084#Do File JOB
085to doOpenImg(listAliasFilePathSorted)
086   
087   
088   set ocidFilePathURLArray to current application's NSMutableArray's alloc()'s init()
089   
090   repeat with aliasItemFilePath in listAliasFilePathSorted
091      set strFilePath to aliasItemFilePath as alias
092      set strFilePath to (POSIX path of strFilePath) as text
093      set ocidFilePathStr to (current application's NSString's stringWithString:(strFilePath))
094      set ocidFilePath to ocidFilePathStr's stringByStandardizingPath()
095      set ocidFilePath to ocidFilePath's stringByExpandingTildeInPath()
096      set ocidFilePathURL to (current application's NSURL's fileURLWithPath:(ocidFilePath) isDirectory:(false))
097      (ocidFilePathURLArray's addObject:(ocidFilePathURL))
098   end repeat
099   
100   #ソート   
101   set ocidDescriptor to current application's NSSortDescriptor's sortDescriptorWithKey:("path") ascending:(yes) selector:("localizedStandardCompare:")
102   set ocidDescriptorArray to current application's NSArray's arrayWithObject:(ocidDescriptor)
103   set ocidSortedArray to ocidFilePathURLArray's sortedArrayUsingDescriptors:(ocidDescriptorArray)
104   
105   #NSWorkspace=Finder
106   set appSharedWorkspace to current application's NSWorkspace's sharedWorkspace()
107   set ocidConfig to current application's NSWorkspaceOpenConfiguration's configuration()
108   (ocidConfig's setActivates:(current application's NSNumber's numberWithBool:true))
109   ocidConfig's setHides:(current application's NSNumber's numberWithBool:false)
110   
111   #MakePDF.app
112   set strAppPath to ("/System/Library/Image Capture/Automatic Tasks/MakePDF.app") as text
113   set ocidAppPathStr to current application's NSString's stringWithString:(strAppPath)
114   set ocidAppPath to ocidAppPathStr's stringByStandardizingPath()
115   set ocidAppPathURL to current application's NSURL's fileURLWithPath:(ocidAppPath) isDirectory:(false)
116   
117   ##
118   (appSharedWorkspace's openURLs:(ocidFilePathURLArray) withApplicationAtURL:(ocidAppPathURL) configuration:(ocidConfig) completionHandler:(missing value))
119   
120   return true
121end doOpenImg
122
AppleScriptで生成しました