NSOpenPanel

[NSOpenPanel]選択できるファイルタイプをUTI指定する


AppleScript サンプルコード

【スクリプトエディタで開く】 |

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
009use AppleScript version "2.8"
010use framework "Foundation"
011use framework "AppKit"
012use framework "UniformTypeIdentifiers"
013use scripting additions
014property refMe : a reference to current application
015property ocidChosenPathURL : missing value
016#設定項目
017property strUTI : ("public.image") as text
018
019on 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|()
052end appChooseFolder:
053
054##デフォルトパス
055set aliasPathToMe to (path to me) as alias
056set strPathToMe to (POSIX path of aliasPathToMe) as text
057set ocidPathToMeStr to refMe's NSString's stringWithString:(strPathToMe)
058set ocidPathToMe to ocidPathToMeStr's stringByStandardizingPath()
059set ocidPathToMeURL to refMe's NSURL's alloc()'s initFileURLWithPath:(ocidPathToMe) isDirectory:(false)
060set ocidContainerDirPathURL to ocidPathToMeURL's URLByDeletingLastPathComponent()
061##ダイアログ呼び出し
062my performSelectorOnMainThread:("appChooseFolder:") withObject:(ocidContainerDirPathURL) waitUntilDone:(true)
063##戻り値NULならキャンセルで停止
064if ocidChosenPathURL = (missing value) then
065  error number -128
066else
067  ##戻り値あるならURL
068  set ocidChosenPathURL to ocidChosenPathURL
069  set strFilePath to ocidChosenPathURL's absoluteString() as text
070  log strFilePath
071end if
072
073
AppleScriptで生成しました

|

NSOpenPanel 


AppleScript サンプルコード

【スクリプトエディタで開く】 |

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
009use AppleScript version "2.8"
010use framework "Foundation"
011use framework "AppKit"
012use scripting additions
013property refMe : a reference to current application
014property ocidChosenPathURL : missing value
015
016on appChooseFolder:(ocidArgDirPathURL)
017  #
018  set ocidOpenPane to refMe's NSOpenPanel's openPanel()
019  #
020  ocidOpenPane's setDirectoryURL:(ocidArgDirPathURL)
021  ocidOpenPane's setCanChooseFiles:(true)
022  ocidOpenPane's setCanChooseDirectories:(true)
023  ocidOpenPane's setAllowsMultipleSelection:(false)
024  ocidOpenPane's setCanCreateDirectories:(true)
025  ocidOpenPane's setAccessoryViewDisclosed:(true)
026  ocidOpenPane's setTitle:"タイトルはやくしない"
027  ocidOpenPane's setPrompt:"実行しちゃうよ♪"
028  ocidOpenPane's setMessage:"ファイルかフォルダ選んでね"
029  ocidOpenPane's setShowsTagField:(true)
030  ocidOpenPane's setResolvesAliases:(false)
031  ocidOpenPane's setShowsHiddenFiles:(true)
032  ocidOpenPane's setExtensionHidden:(false)
033  ocidOpenPane's setCanDownloadUbiquitousContents:(true)
034  ocidOpenPane's setCanResolveUbiquitousConflicts:(true)
035  #
036  set returnCode to ocidOpenPane's runModal()
037  #キャンセルをmissing value
038  if returnCode = (refMe's NSFileHandlingPanelCancelButton) then
039    error number -128
040  end if
041  #戻しURL
042  set my ocidChosenPathURL to ocidOpenPane's |URL|()
043end appChooseFolder:
044
045##デフォルトパス
046set aliasPathToMe to (path to me) as alias
047set strPathToMe to (POSIX path of aliasPathToMe) as text
048set ocidPathToMeStr to refMe's NSString's stringWithString:(strPathToMe)
049set ocidPathToMe to ocidPathToMeStr's stringByStandardizingPath()
050set ocidPathToMeURL to refMe's NSURL's alloc()'s initFileURLWithPath:(ocidPathToMe) isDirectory:(false)
051set ocidContainerDirPathURL to ocidPathToMeURL's URLByDeletingLastPathComponent()
052##ダイアログ呼び出し
053my performSelectorOnMainThread:("appChooseFolder:") withObject:(ocidContainerDirPathURL) waitUntilDone:(true)
054##戻り値NULならキャンセルで停止
055if ocidChosenPathURL = (missing value) then
056  error number -128
057else
058  ##戻り値あるならURL
059  set ocidChosenPathURL to ocidChosenPathURL
060  set strFilePath to ocidChosenPathURL's absoluteString() as text
061  log strFilePath
062end if
063
064
AppleScriptで生成しました

|

[NSOpenPanel] NSOpenPanelはアプリケーションで利用可能

NSOpenPanelは、書き出してコンパイルされたアプリケーションからのみ利用可能(現時点)
ファイルもフォルダも選択できるので
使いたいけどなぁ



#!/usr/bin/env osascript
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7
#
#
#
#
# com.cocolog-nifty.quicktimer.icefloe
----+----1----+----2----+-----3----+----4----+----5----+----6----+----7

use AppleScript version "2.8"
use framework "Foundation"
use framework "AppKit"
use scripting additions
property refMe : a reference to current application
property refNSURL : a reference to refMe's NSURL
property refNSArray : a reference to refMe's NSArray

property refNSOpenPanel : a reference to refMe's NSOpenPanel


set ocidOpenPane to refNSOpenPanel's openPanel
ocidOpenPane's setCanChooseFiles:true
ocidOpenPane's setCanChooseDirectories:false

ocidOpenPane's setDirectoryURL:(refNSURL's fileURLWithPath:"/Users/")

ocidOpenPane's setAllowsMultipleSelection:true
ocidOpenPane's setCanCreateDirectories:true
ocidOpenPane's setTitle:"タイトルはやくしない"
ocidOpenPane's setPrompt:"実行しちゃうよ♪"
ocidOpenPane's setMessage:"ファイルかフォルダ選んでね"
ocidOpenPane's setShowsTagField:true
ocidOpenPane's setResolvesAliases:true
ocidOpenPane's setShowsHiddenFiles:true
ocidOpenPane's setExtensionHidden:false

ocidOpenPane's setCanDownloadUbiquitousContents:false
ocidOpenPane's setCanResolveUbiquitousConflicts:false
ocidOpenPane's runModal()

|

その他のカテゴリー

Accessibility Acrobat Acrobat 2020 Acrobat AddOn Acrobat Annotation Acrobat ARMDC Acrobat AV2 Acrobat BookMark Acrobat Classic Acrobat DC Acrobat Dialog Acrobat Distiller Acrobat Form Acrobat JS Acrobat Manifest Acrobat Menu Acrobat Open Acrobat Plugin Acrobat Preferences Acrobat Preflight Acrobat python Acrobat Reader Acrobat SCA Acrobat SCA Updater Acrobat Sequ Acrobat Sign Acrobat Stamps Acrobat Watermark Acrobat Windows Acrobat Windows Reader Admin Admin Account Admin Apachectl Admin configCode Admin Device Management Admin LaunchServices Admin Locationd Admin loginitem Admin Maintenance Admin Mobileconfig Admin Permission Admin Pkg Admin Power Management Admin Printer Admin SetUp Admin SMB Admin Support Admin System Information Admin Tools Admin Users Admin Volumes Adobe Adobe FDKO Adobe RemoteUpdateManager AppKit Apple AppleScript AppleScript do shell script AppleScript List AppleScript ObjC AppleScript Osax AppleScript PDF AppleScript Pictures AppleScript record AppleScript Script Editor AppleScript Script Menu AppleScript Shortcuts AppleScript Shortcuts Events AppleScript System Events AppleScript System Events Plist AppleScript Video Applications AppStore Archive Attributes Automator BackUp Barcode Barcode QR Barcode QR Decode Bash Basic Basic Path Bluetooth BOX Browser Calendar CD/DVD Choose Chrome CIImage CityCode CloudStorage Color com.apple.LaunchServices.OpenWith Console Contacts CotEditor CURL current application Date&Time delimiters Desktop Device Diff Disk Dock DropBox Droplet eMail Encode % Encode Decode Encode UTF8 Error EXIFData ffmpeg File Finder Firefox Folder FolderAction Fonts GIF github Guide HTML HTML Entity Icon Illustrator Image Events Image2PDF ImageOptim iPhone iWork Javascript Jedit Json Label Leading Zero List locationd LRC lsappinfo LSSharedFileList m3u8 Mail MakePDF Map Math Media Media AVAsset Media AVconvert Media AVFoundation Media AVURLAsset Media Movie Media Music Memo Messages Microsoft Microsoft Edge Microsoft Excel Mouse Music NetWork Notes NSArray NSArray Sort NSBezierPath NSBitmapImageRep NSBundle NSCFBoolean NSCharacterSet NSColor NSColorList NSData NSDecimalNumber NSDictionary NSError NSEvent NSFileAttributes NSFileManager NSFileManager enumeratorAtURL NSFont NSFontManager NSGraphicsContext NSImage NSIndex NSKeyedArchiver NSKeyedUnarchiver NSLocale NSMutableArray NSMutableDictionary NSMutableString NSNotFound NSNumber NSOpenPanel NSPasteboard NSpoint NSPredicate NSPrintOperation NSRange NSRect NSRegularExpression NSRunningApplication NSScreen NSSize NSString NSString stringByApplyingTransform NSStringCompareOptions NSTask NSTimeZone NSURL NSURL File NSURLBookmark NSURLComponents NSURLResourceKey NSURLSession NSUserDefaults NSUUID NSView NSWorkspace Numbers OAuth OneDrive PDF PDFAnnotation PDFAnnotationWidget PDFContext PDFDisplayBox PDFDocumentPermissions PDFImageRep PDFKit PDFnUP PDFOutline perl Photoshop PlistBuddy pluginkit postalcode PostScript prefPane Preview Python QuickLook QuickTime ReadMe Regular Expression Reminders ReName Repeat RTF Safari SaveFile ScreenCapture ScreenSaver SF Symbols character id SF Symbols Entity sips Skype Slack Sound Spotlight sqlite SRT StandardAdditions Swift System Settings TCC TemporaryItems Terminal Text Text CSV Text MD Text TSV TextEdit Tools Translate Trash Twitter Typography UI Unit Conversion UTType valueForKeyPath Video VisionKit Visual Studio Code Wacom webarchive webp Wifi Windows XML XML EPUB XML OPML XML Plist XML RSS XML savedSearch XML SVG XML TTML XML webloc XML XMP YouTube zoom