20260614

AS記法 MakePDF ファイル指定

AS記法 MakePDF ファイル指定

NOTE記事一覧ですnote.com

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

[AS]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 scripting additions
010
011
012########################
013# RUN
014on run
015   #on run  {listAliasFilePath}
016   
017   ########################
018   #Dialog
019   set strMsg to ("Choose file") as text
020   set strPrompt to ("Choose file" & return & "multiple selections allowed") as text
021   set aliasDesktopDirPath to (path to desktop from user domain) as alias
022   set listUTI to {"public.item"} as list
023   try
024      tell application "Finder"
025         #Finderから呼び出すことでスクリプトアプリケーションになってもダイアログがマルチリンガルになります
026         #By calling from Finder, the dialog becomes multilingual even if it becomes a script application.
027         tell application "SystemUIServer"
028            activate
029            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
030         end tell
031      end tell
032   on error strErrMes number numErrNo
033      log strErrMes & numErrNo
034      return false
035   end try
036   
037   set boolDone to (open listAliasFilePath) as boolean
038   return boolDone
039end run
040
041########################
042# OPEN
043on open listAliasFilePath
044   #次工程に回すリスト List to be transferred to the next process
045   set listImgFilePath to {} as list
046   #IMAGE UTI
047   set listImageUTI to {"public.image", "public.png", "public.tiff", "public.jpeg", "public.heic"} as list
048   
049   
050   repeat with itemAliasFilePath in listAliasFilePath
051      #エイリアス確定 Alias confirmed
052      set aliasItemFilePath to itemAliasFilePath as alias
053      #ファイルINFOを取得 Get the file INFO
054      set recordInfoFor to (info for aliasItemFilePath) as record
055      #フォルダ判定
056      set boolIsDir to (folder of recordInfoFor) as boolean
057      
058      if boolIsDir is true then
059         #フォルダなら IS DIR
060         set boolDone to doFolderJon(aliasItemFilePath) as boolean
061         
062      else if boolIsDir is false then
063         #ファイルなら IS FILE
064         set strUTI to (type identifier of recordInfoFor) as text
065         #UTIが対象ファイルなら
066         if listImageUTI contains strUTI then
067            #エイリアスリストに追加
068            set beginning of listImgFilePath to aliasItemFilePath
069         end if
070      end if
071      
072   end repeat
073   
074   #本処理に回す Turn to this processing
075   set boolDone to doOpenFileList(listImgFilePath)
076   
077   return true
078end open
079
080
081########################
082#Do Folder JOB
083to doFolderJon(argAliasFilePath)
084   
085   return false
086end doFolderJon
087
088########################
089#OPEN MakePDF2IMAGE
090to doOpenFileList(listImgFilePath)
091   tell application "Finder"
092      set listAliasImgFilePath to listImgFilePath as alias list
093      set listAliasFilePathSorted to (sort of listAliasImgFilePath by name) as alias list
094      open listAliasFilePathSorted using application file id "com.apple.MakePDF"
095   end tell
096   return true
097end doOpenFileList
098
AppleScriptで生成しました