iCloud driveの書類を開く
AppleScript サンプルコード
行番号 | ソース |
---|---|
001 | #!/usr/bin/env osascript |
002 | ----+----1----+----2----+-----3----+----4----+----5----+----6----+----7 |
003 | # com.cocolog-nifty.quicktimer.icefloe |
004 | # |
005 | # |
006 | ----+----1----+----2----+-----3----+----4----+----5----+----6----+----7 |
007 | use AppleScript version "2.8" |
008 | use framework "Foundation" |
009 | use framework "AppKit" |
010 | use scripting additions |
011 | |
012 | property refMe : a reference to current application |
013 | |
014 | ## |
015 | set appFileManager to refMe's NSFileManager's defaultManager() |
016 | set ocidURLsArray to (appFileManager's URLsForDirectory:(refMe's NSLibraryDirectory) inDomains:(refMe's NSUserDomainMask)) |
017 | set ocidLibraryDirPathURL to ocidURLsArray's firstObject() |
018 | set ocidiCloudDirPathURL to ocidLibraryDirPathURL's URLByAppendingPathComponent:("Mobile Documents") isDirectory:(true) |
019 | set aliasiCloudDirPath to (ocidiCloudDirPathURL's absoluteURL()) as alias |
020 | |
021 | ############################# |
022 | #ダイアログ |
023 | set strName to (name of current application) as text |
024 | if strName is "osascript" then |
025 | tell application "Finder" to activate |
026 | else |
027 | tell current application to activate |
028 | end if |
029 | set listUTI to {"public.item"} |
030 | set strMes to ("ファイルを選んでください") as text |
031 | set strPrompt to ("ファイルを選んでください") as text |
032 | try |
033 | ### ファイル選択時 |
034 | set aliasFilePath to (choose file strMes with prompt strPrompt default location (aliasiCloudDirPath) of type listUTI with invisibles and showing package contents without multiple selections allowed) as alias |
035 | on error |
036 | log "エラーしました" |
037 | return "エラーしました" |
038 | end try |
039 | ##選んだファイル |
040 | set strFilePath to (POSIX path of aliasFilePath) as text |
041 | set ocidFilePathStr to refMe's NSString's stringWithString:(strFilePath) |
042 | set ocidFilePath to ocidFilePathStr's stringByStandardizingPath() |
043 | set ocidTargetFilePathURL to (refMe's NSURL's alloc()'s initFileURLWithPath:(ocidFilePath) isDirectory:false) |
044 | |
045 | ##iCloudファイルか?確認 |
046 | set listResponse to ocidTargetFilePathURL's getResourceValue:(reference) forKey:(refMe's NSURLIsUbiquitousItemKey) |error| :(reference) |
047 | set boolIsUbiquitou to (item 2 of listResponse) |
048 | #iCloudデータの場合は |
049 | if boolIsUbiquitou is true then |
050 | log "iCloudデータです" |
051 | ##まずはダウンロードを試みて |
052 | set listDone to appFileManager's startDownloadingUbiquitousItemAtURL:(ocidTargetFilePathURL) |error| :(reference) |
053 | if (item 2 of listDone) is true then |
054 | log "正常処理" |
055 | else if (item 2 of listDone) ≠ (missing value) then |
056 | set strErrorNO to (item 2 of listDone)'s code() as text |
057 | set strErrorMes to (item 2 of listDone)'s localizedDescription() as text |
058 | refMe's NSLog("■:" & strErrorNO & strErrorMes) |
059 | return "エラーしました" & strErrorNO & strErrorMes |
060 | end if |
061 | end if |
062 | |
063 | |
064 | ##エラーがなければ開く |
065 | set appSharedWorkspace to refMe's NSWorkspace's sharedWorkspace() |
066 | set boolDone to appSharedWorkspace's openURL:(ocidTargetFilePathURL) |
067 | |
068 | |
AppleScriptで生成しました |
| 固定リンク