
OBJC記法 WEBページ作成 フォルダ指定
【Safari・FireFox用Script Editorで開く】 |
| ソース | |
|---|---|
| 001 | #!/usr/bin/env osascript |
| 002 | #coding: utf-8 |
| 003 | ----+----1----+----2----+-----3----+----4----+----5----+----6----+----7 |
| 004 | (* |
| 005 | WEBページ作成 |
| 006 | フォルダ選択して中にある画像ファイルで処理 |
| 007 | |
| 008 | |
| 009 | com.cocolog-nifty.quicktimer.icefloe *) |
| 010 | ----+----1----+----2----+-----3----+----4----+----5----+----6----+----7 |
| 011 | use AppleScript version "2.8" |
| 012 | use framework "Foundation" |
| 013 | use framework "UniformTypeIdentifiers" |
| 014 | use framework "AppKit" |
| 015 | use scripting additions |
| 016 | |
| 017 | property refMe : a reference to current application |
| 018 | |
| 019 | set strBundleID to ("com.apple.BuildWebPage") as text |
| 020 | |
| 021 | ####終了させてから処理させる |
| 022 | tell application id strBundleID to quit |
| 023 | |
| 024 | ####半ゾンビ対策 |
| 025 | set ocidRunningApplication to refMe's NSRunningApplication |
| 026 | set ocidAppArray to ocidRunningApplication's runningApplicationsWithBundleIdentifier:(strBundleID) |
| 027 | repeat with itemAppArray in ocidAppArray |
| 028 | itemAppArray's terminate |
| 029 | end repeat |
| 030 | |
| 031 | ############################# |
| 032 | ###ダイアログ |
| 033 | tell current application |
| 034 | set strName to name as text |
| 035 | end tell |
| 036 | ###ダイアログを前面に出す |
| 037 | if strName is "osascript" then |
| 038 | tell application "Finder" to activate |
| 039 | else |
| 040 | tell current application to activate |
| 041 | end if |
| 042 | |
| 043 | ############ |
| 044 | set appFileManager to refMe's NSFileManager's defaultManager() |
| 045 | set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSDesktopDirectory) inDomains:(refMe's NSUserDomainMask)) |
| 046 | set ocidDesktopDirPathURL to ocidURLsArray's firstObject() |
| 047 | set aliasDefaultLocation to (ocidDesktopDirPathURL's absoluteURL()) as alias |
| 048 | ############ |
| 049 | set strMes to "フォルダを選んでください" as text |
| 050 | set strPrompt to "フォルダを選択してください" as text |
| 051 | try |
| 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 |
| 060 | on error |
| 061 | log "エラーしました" |
| 062 | return "エラーしました" |
| 063 | end try |
| 064 | |
| 065 | tell application id strBundleID to launch |
| 066 | repeat 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 |
| 078 | end repeat |
| 079 | |
| 080 | |
| 081 | |
| 082 | |
| 083 | set strAppPath to ("/System/Library/Image Capture/Automatic Tasks/Build Web Page.app") as text |
| 084 | set ocidAppPathStr to refMe's NSString's stringWithString:(strAppPath) |
| 085 | set ocidAppPath to ocidAppPathStr's stringByStandardizingPath() |
| 086 | set ocidAppPathURL to refMe's NSURL's fileURLWithPath:(ocidAppPath) isDirectory:(false) |
| 087 | |
| 088 | |
| 089 | |
| 090 | |
| 091 | |
| 092 | repeat 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 | |
| 117 | end repeat |
| 118 | |
| 119 | ###保存先を開く |
| 120 | delay 3 |
| 121 | |
| 122 | set appFileManager to refMe's NSFileManager's defaultManager() |
| 123 | set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSPicturesDirectory) inDomains:(refMe's NSUserDomainMask)) |
| 124 | set ocidPicturesDirPathURL to ocidURLsArray's firstObject() |
| 125 | |
| 126 | #コンテンツの収集 |
| 127 | set appFileManager to refMe's NSFileManager's defaultManager() |
| 128 | set ocidOption to (refMe's NSDirectoryEnumerationSkipsHiddenFiles) |
| 129 | set ocidKeyArray to refMe's NSMutableArray's alloc()'s init() |
| 130 | ocidKeyArray's addObject:(refMe's NSURLPathKey) |
| 131 | ocidKeyArray's addObject:(refMe's NSURLIsDirectoryKey) |
| 132 | ocidKeyArray's addObject:(refMe's NSURLCreationDateKey) |
| 133 | set listResponse to (appFileManager's contentsOfDirectoryAtURL:(ocidPicturesDirPathURL) includingPropertiesForKeys:(ocidKeyArray) options:(ocidOption) |error|:(reference)) |
| 134 | set ocidSubPathURLArray to (first item of listResponse) |
| 135 | # |
| 136 | set appPredicate to refMe's NSPredicate's predicateWithFormat:("lastPathComponent CONTAINS 'Webページ on'") |
| 137 | set ocidFilteredArray to ocidSubPathURLArray's filteredArrayUsingPredicate:(appPredicate) |
| 138 | # |
| 139 | set ocidDescriptor to refMe's NSSortDescriptor's sortDescriptorWithKey:("lastPathComponent") ascending:(yes) selector:("localizedStandardCompare:") |
| 140 | set ocidDescriptorArray to refMe's NSArray's arrayWithObject:(ocidDescriptor) |
| 141 | set ocidSortedArray to ocidFilteredArray's sortedArrayUsingDescriptors:(ocidDescriptorArray) |
| 142 | set ocidOpenURL to ocidSortedArray's lastObject() |
| 143 | # |
| 144 | set appSharedWorkspace to refMe's NSWorkspace's sharedWorkspace() |
| 145 | set boolDone to appSharedWorkspace's openURL:(ocidOpenURL) |
| 146 | set appFinderArray to refMe's NSRunningApplication's runningApplicationsWithBundleIdentifier:("com.apple.finder") |
| 147 | set appFinder to appFinderArray's firstObject() |
| 148 | set boolDone to appFinder's activateWithOptions:(refMe's NSApplicationActivateIgnoringOtherApps) |
| 149 | |
| 150 | return true |
| AppleScriptで生成しました | |
