20260614

OBJC記法 WEBページ作成 フォルダ指定

OBJC記法 WEBページ作成 フォルダ指定

NOTE記事一覧ですnote.com

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

OBJC BuildWebPage.applescript.scpt
ソース
001#!/usr/bin/env osascript
002#coding: utf-8
003----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
004(*
005WEBページ作成
006フォルダ選択して中にある画像ファイルで処理
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 "UniformTypeIdentifiers"
014use framework "AppKit"
015use scripting additions
016
017property refMe : a reference to current application
018
019set strBundleID to ("com.apple.BuildWebPage") as text
020
021####終了させてから処理させる
022tell application id strBundleID to quit
023
024####半ゾンビ対策   
025set ocidRunningApplication to refMe's NSRunningApplication
026set ocidAppArray to ocidRunningApplication's runningApplicationsWithBundleIdentifier:(strBundleID)
027repeat with itemAppArray in ocidAppArray
028   itemAppArray's terminate
029end repeat
030
031#############################
032###ダイアログ
033tell current application
034   set strName to name as text
035end tell
036###ダイアログを前面に出す
037if strName is "osascript" then
038   tell application "Finder" to activate
039else
040   tell current application to activate
041end if
042
043############
044set appFileManager to refMe's NSFileManager's defaultManager()
045set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSDesktopDirectory) inDomains:(refMe's NSUserDomainMask))
046set ocidDesktopDirPathURL to ocidURLsArray's firstObject()
047set aliasDefaultLocation to (ocidDesktopDirPathURL's absoluteURL()) as alias
048############
049set strMes to "フォルダを選んでください" as text
050set strPrompt to "フォルダを選択してください" as text
051try
052   tell application "Finder"
053      #Finderから呼び出すことでスクリプトアプリケーションになってもダイアログがマルチリンガルになります
054      #By calling from Finder, the dialog becomes multilingual even if it becomes a script application.
055      tell application "SystemUIServer"
056         activate
057         set listAliasFolderPath to (choose folder strMes with prompt strPrompt default location aliasDefaultLocation with multiple selections allowed without invisibles and showing package contents) as list
058      end tell
059   end tell
060on error
061   log "エラーしました"
062   return "エラーしました"
063end try
064
065tell application id strBundleID to launch
066repeat 10 times
067   try
068      tell application id strBundleID to activate
069   end try
070   set boolFontmost to frontmost of (application id strBundleID)
071   if boolFontmost is false then
072      delay 1
073      tell application id strBundleID to launch
074   else
075      tell application id strBundleID to activate
076      exit repeat
077   end if
078end repeat
079
080
081
082
083set strAppPath to ("/System/Library/Image Capture/Automatic Tasks/Build Web Page.app") as text
084set ocidAppPathStr to refMe's NSString's stringWithString:(strAppPath)
085set ocidAppPath to ocidAppPathStr's stringByStandardizingPath()
086set ocidAppPathURL to refMe's NSURL's fileURLWithPath:(ocidAppPath) isDirectory:(false)
087
088
089
090
091
092repeat with objAliasFolderPath in listAliasFolderPath
093   set aliasFolderPath to objAliasFolderPath as alias
094   
095   
096   set strDirPath to (POSIX path of aliasFolderPath) as text
097   set ocidDirPathStr to (refMe's NSString's stringWithString:(strDirPath))
098   set ocidDirPathStr to ocidDirPathStr's precomposedStringWithCanonicalMapping()
099   set ocidDirPath to ocidDirPathStr's stringByStandardizingPath()
100   set ocidDirPath to ocidDirPath's stringByExpandingTildeInPath()
101   set ocidDirPathURL to (refMe's NSURL's fileURLWithPath:(ocidDirPath) isDirectory:(true))
102   
103   
104   
105   set appSharedWorkspace to refMe's NSWorkspace's sharedWorkspace()
106   set ocidConfig to refMe's NSWorkspaceOpenConfiguration's configuration
107   (ocidConfig's setActivates:(refMe's NSNumber's numberWithBool:true))
108   (ocidConfig's setHides:(refMe's NSNumber's numberWithBool:false))
109   ##
110   set ocidOpenURLsArray to refMe's NSMutableArray's alloc()'s init()
111   (ocidOpenURLsArray's addObject:(ocidDirPathURL))
112   ##
113   (appSharedWorkspace's openURLs:(ocidOpenURLsArray) withApplicationAtURL:(ocidAppPathURL) configuration:(ocidConfig) completionHandler:(missing value))
114   
115   
116   
117end repeat
118
119###保存先を開く
120delay 3
121
122set appFileManager to refMe's NSFileManager's defaultManager()
123set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSPicturesDirectory) inDomains:(refMe's NSUserDomainMask))
124set ocidPicturesDirPathURL to ocidURLsArray's firstObject()
125
126#コンテンツの収集
127set appFileManager to refMe's NSFileManager's defaultManager()
128set ocidOption to (refMe's NSDirectoryEnumerationSkipsHiddenFiles)
129set ocidKeyArray to refMe's NSMutableArray's alloc()'s init()
130ocidKeyArray's addObject:(refMe's NSURLPathKey)
131ocidKeyArray's addObject:(refMe's NSURLIsDirectoryKey)
132ocidKeyArray's addObject:(refMe's NSURLCreationDateKey)
133set listResponse to (appFileManager's contentsOfDirectoryAtURL:(ocidPicturesDirPathURL) includingPropertiesForKeys:(ocidKeyArray) options:(ocidOption) |error|:(reference))
134set ocidSubPathURLArray to (first item of listResponse)
135#
136set appPredicate to refMe's NSPredicate's predicateWithFormat:("lastPathComponent CONTAINS 'Webページ on'")
137set ocidFilteredArray to ocidSubPathURLArray's filteredArrayUsingPredicate:(appPredicate)
138#
139set ocidDescriptor to refMe's NSSortDescriptor's sortDescriptorWithKey:("lastPathComponent") ascending:(yes) selector:("localizedStandardCompare:")
140set ocidDescriptorArray to refMe's NSArray's arrayWithObject:(ocidDescriptor)
141set ocidSortedArray to ocidFilteredArray's sortedArrayUsingDescriptors:(ocidDescriptorArray)
142set ocidOpenURL to ocidSortedArray's lastObject()
143#
144set appSharedWorkspace to refMe's NSWorkspace's sharedWorkspace()
145set boolDone to appSharedWorkspace's openURL:(ocidOpenURL)
146set appFinderArray to refMe's NSRunningApplication's runningApplicationsWithBundleIdentifier:("com.apple.finder")
147set appFinder to appFinderArray's firstObject()
148set boolDone to appFinder's activateWithOptions:(refMe's NSApplicationActivateIgnoringOtherApps)
149
150return true
AppleScriptで生成しました