[NSOpenPanel]選択できるファイルタイプをUTI指定する
AppleScript サンプルコード
行番号 | ソース |
---|---|
001 | #!/usr/bin/env osascript |
002 | ----+----1----+----2----+-----3----+----4----+----5----+----6----+----7 |
003 | # |
004 | # |
005 | # |
006 | # |
007 | # com.cocolog-nifty.quicktimer.icefloe |
008 | ----+----1----+----2----+-----3----+----4----+----5----+----6----+----7 |
009 | use AppleScript version "2.8" |
010 | use framework "Foundation" |
011 | use framework "AppKit" |
012 | use framework "UniformTypeIdentifiers" |
013 | use scripting additions |
014 | property refMe : a reference to current application |
015 | property ocidChosenPathURL : missing value |
016 | #設定項目 |
017 | property strUTI : ("public.image") as text |
018 | |
019 | on appChooseFolder:(ocidArgDirPathURL) |
020 | # |
021 | set ocidOpenPane to refMe's NSOpenPanel's openPanel() |
022 | # |
023 | ocidOpenPane's setDirectoryURL:(ocidArgDirPathURL) |
024 | ocidOpenPane's setCanChooseFiles:(true) |
025 | ocidOpenPane's setCanChooseDirectories:(true) |
026 | ocidOpenPane's setAllowsMultipleSelection:(false) |
027 | ocidOpenPane's setCanCreateDirectories:(true) |
028 | ocidOpenPane's setAccessoryViewDisclosed:(true) |
029 | ocidOpenPane's setTitle:"タイトルはやくしない" |
030 | ocidOpenPane's setPrompt:"実行しちゃうよ♪" |
031 | ocidOpenPane's setMessage:"ファイルかフォルダ選んでね" |
032 | ocidOpenPane's setShowsTagField:(true) |
033 | ocidOpenPane's setResolvesAliases:(false) |
034 | ocidOpenPane's setShowsHiddenFiles:(true) |
035 | ocidOpenPane's setExtensionHidden:(false) |
036 | ocidOpenPane's setCanDownloadUbiquitousContents:(true) |
037 | ocidOpenPane's setCanResolveUbiquitousConflicts:(true) |
038 | # |
039 | set ocidUTType to refMe's UTType's typeWithIdentifier:(strUTI) |
040 | set ocidUTTypeArray to refMe's NSMutableArray's alloc()'s initWithCapacity:(0) |
041 | ocidUTTypeArray's addObject:(ocidUTType) |
042 | ocidOpenPane's setAllowedContentTypes:(ocidUTTypeArray) |
043 | ocidOpenPane's setAllowsOtherFileTypes:(false) |
044 | # |
045 | set returnCode to ocidOpenPane's runModal() |
046 | #キャンセルをmissing value |
047 | if returnCode = (refMe's NSFileHandlingPanelCancelButton) then |
048 | error number -128 |
049 | end if |
050 | #戻しURL |
051 | set my ocidChosenPathURL to ocidOpenPane's |URL|() |
052 | end appChooseFolder: |
053 | |
054 | ##デフォルトパス |
055 | set aliasPathToMe to (path to me) as alias |
056 | set strPathToMe to (POSIX path of aliasPathToMe) as text |
057 | set ocidPathToMeStr to refMe's NSString's stringWithString:(strPathToMe) |
058 | set ocidPathToMe to ocidPathToMeStr's stringByStandardizingPath() |
059 | set ocidPathToMeURL to refMe's NSURL's alloc()'s initFileURLWithPath:(ocidPathToMe) isDirectory:(false) |
060 | set ocidContainerDirPathURL to ocidPathToMeURL's URLByDeletingLastPathComponent() |
061 | ##ダイアログ呼び出し |
062 | my performSelectorOnMainThread:("appChooseFolder:") withObject:(ocidContainerDirPathURL) waitUntilDone:(true) |
063 | ##戻り値NULならキャンセルで停止 |
064 | if ocidChosenPathURL = (missing value) then |
065 | error number -128 |
066 | else |
067 | ##戻り値あるならURL |
068 | set ocidChosenPathURL to ocidChosenPathURL |
069 | set strFilePath to ocidChosenPathURL's absoluteString() as text |
070 | log strFilePath |
071 | end if |
072 | |
073 | |
AppleScriptで生成しました |
| 固定リンク