20260614

OBJC記法 WEBページ作成 ファイル指定

OBJC記法 WEBページ作成 ファイル指定

NOTE記事一覧ですnote.com

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

[OBJC]Img2BuildWebPage.scpt.scpt
ソース
001#!/usr/bin/env osascript
002#coding: utf-8
003----+----1----+----2----+-----3----+----4----+----5----+----6----+----7--
004(*
005
006OBJC記法 WEBページ作成 ファイル指定
007
008
009com.cocolog-nifty.quicktimer.icefloe *)
010----+----1----+----2----+-----3----+----4----+----5----+----6----+----7--
011use AppleScript version "2.8"
012use framework "Foundation"
013use framework "AppKit"
014use scripting additions
015
016########################
017# RUN
018on run
019   #{listAliasFilePath}
020   
021   
022   ########################
023   #Dialog
024   set strMsg to ("Choose file") as text
025   set strPrompt to ("Choose file" & return & "multiple selections allowed") as text
026   set aliasDesktopDirPath to (path to desktop from user domain) as alias
027   set listUTI to {"public.item"} as list
028   try
029      tell application "Finder"
030         #Finderから呼び出すことでスクリプトアプリケーションになってもダイアログがマルチリンガルになります
031         #By calling from Finder, the dialog becomes multilingual even if it becomes a script application.
032         tell application "SystemUIServer"
033            activate
034            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
035         end tell
036      end tell
037   on error strErrMes number numErrNo
038      log strErrMes & numErrNo
039      return false
040   end try
041   
042   
043   set boolDone to (open listAliasFilePath) as boolean
044   return boolDone
045end run
046
047########################
048# OPEN
049on open listAliasFilePath
050   
051   set listImgFilePath to {} as list
052   
053   set listImageUTI to {"public.image", "public.png", "public.tiff", "public.jpeg", "public.heic"} as list
054   
055   
056   repeat with itemAliasFilePath in listAliasFilePath
057      set aliasItemFilePath to itemAliasFilePath as alias
058      set recordInfoFor to (info for aliasItemFilePath) as record
059      set boolIsDir to (folder of recordInfoFor) as boolean
060      if boolIsDir is true then
061         set boolDone to doFolderJon(aliasItemFilePath) as boolean
062      else if boolIsDir is false then
063         set strUTI to (type identifier of recordInfoFor) as text
064         if listImageUTI contains strUTI then
065            set end of listImgFilePath to aliasItemFilePath
066         end if
067      end if
068      
069   end repeat
070   
071   
072   set boolDone to doOpenImg(listImgFilePath)
073   
074   
075   
076   ###保存先を開く
077   delay 3
078   
079   set appFileManager to current application's NSFileManager's defaultManager()
080   set ocidURLsArray to (appFileManager's URLsForDirectory:(current application's NSPicturesDirectory) inDomains:(current application's NSUserDomainMask))
081   set ocidPicturesDirPathURL to ocidURLsArray's firstObject()
082   
083   #コンテンツの収集
084   set appFileManager to current application's NSFileManager's defaultManager()
085   set ocidOption to (current application's NSDirectoryEnumerationSkipsHiddenFiles)
086   set ocidKeyArray to current application's NSMutableArray's alloc()'s init()
087   ocidKeyArray's addObject:(current application's NSURLPathKey)
088   ocidKeyArray's addObject:(current application's NSURLIsDirectoryKey)
089   ocidKeyArray's addObject:(current application's NSURLCreationDateKey)
090   set listResponse to (appFileManager's contentsOfDirectoryAtURL:(ocidPicturesDirPathURL) includingPropertiesForKeys:(ocidKeyArray) options:(ocidOption) |error|:(reference))
091   set ocidSubPathURLArray to (first item of listResponse)
092   #
093   set appPredicate to current application's NSPredicate's predicateWithFormat:("lastPathComponent CONTAINS 'Webページ on'")
094   set ocidFilteredArray to ocidSubPathURLArray's filteredArrayUsingPredicate:(appPredicate)
095   #
096   set ocidDescriptor to current application's NSSortDescriptor's sortDescriptorWithKey:("lastPathComponent") ascending:(yes) selector:("localizedStandardCompare:")
097   set ocidDescriptorArray to current application's NSArray's arrayWithObject:(ocidDescriptor)
098   set ocidSortedArray to ocidFilteredArray's sortedArrayUsingDescriptors:(ocidDescriptorArray)
099   set ocidOpenURL to ocidSortedArray's lastObject()
100   #
101   set appSharedWorkspace to current application's NSWorkspace's sharedWorkspace()
102   set boolDone to appSharedWorkspace's openURL:(ocidOpenURL)
103   set appFinderArray to current application's NSRunningApplication's runningApplicationsWithBundleIdentifier:("com.apple.finder")
104   set appFinder to appFinderArray's firstObject()
105   set boolDone to appFinder's activateWithOptions:(current application's NSApplicationActivateIgnoringOtherApps)
106   
107   
108   
109   return true
110end open
111
112
113########################
114#Do Folder JOB
115to doFolderJon(argAliasFilePath)
116   
117   return false
118end doFolderJon
119
120
121########################
122#Do File JOB
123to doOpenImg(listAliasFilePathSorted)
124   
125   
126   set ocidFilePathURLArray to current application's NSMutableArray's alloc()'s init()
127   
128   repeat with aliasItemFilePath in listAliasFilePathSorted
129      set strFilePath to aliasItemFilePath as alias
130      set strFilePath to (POSIX path of strFilePath) as text
131      set ocidFilePathStr to (current application's NSString's stringWithString:(strFilePath))
132      set ocidFilePath to ocidFilePathStr's stringByStandardizingPath()
133      set ocidFilePath to ocidFilePath's stringByExpandingTildeInPath()
134      set ocidFilePathURL to (current application's NSURL's fileURLWithPath:(ocidFilePath) isDirectory:(false))
135      (ocidFilePathURLArray's addObject:(ocidFilePathURL))
136   end repeat
137   
138   #ソート   
139   set ocidDescriptor to current application's NSSortDescriptor's sortDescriptorWithKey:("path") ascending:(yes) selector:("localizedStandardCompare:")
140   set ocidDescriptorArray to current application's NSArray's arrayWithObject:(ocidDescriptor)
141   set ocidSortedArray to ocidFilePathURLArray's sortedArrayUsingDescriptors:(ocidDescriptorArray)
142   
143   #NSWorkspace=Finder
144   set appSharedWorkspace to current application's NSWorkspace's sharedWorkspace()
145   set ocidConfig to current application's NSWorkspaceOpenConfiguration's configuration()
146   (ocidConfig's setActivates:(current application's NSNumber's numberWithBool:true))
147   ocidConfig's setHides:(current application's NSNumber's numberWithBool:false)
148   
149   #MakePDF.app
150   set strAppPath to ("/System/Library/Image Capture/Automatic Tasks/Build Web Page.app") as text
151   set ocidAppPathStr to current application's NSString's stringWithString:(strAppPath)
152   set ocidAppPath to ocidAppPathStr's stringByStandardizingPath()
153   set ocidAppPathURL to current application's NSURL's fileURLWithPath:(ocidAppPath) isDirectory:(false)
154   
155   ##
156   (appSharedWorkspace's openURLs:(ocidFilePathURLArray) withApplicationAtURL:(ocidAppPathURL) configuration:(ocidConfig) completionHandler:(missing value))
157   
158   return true
159end doOpenImg
160
AppleScriptで生成しました