Finder上で選択中のアプリケーションのplistファイルを探してFinder上で選択表示するAppleScriptです。
AppleScript名:display selected application’s plist on Finder.scpt |
— – Created by: Takaaki Naganoya – Created on: 2020/08/17 — – Copyright © 2020 Piyomaru Software, All Rights Reserved — use AppleScript version "2.5" –macOS 10.11 or later use scripting additions use framework "Foundation" use framework "AppKit" property |NSURL| : a reference to current application’s |NSURL| property NSArray : a reference to current application’s NSArray property NSPredicate : a reference to current application’s NSPredicate property NSURLTypeIdentifierKey : a reference to current application’s NSURLTypeIdentifierKey tell application "Finder" set aliasList to selection as alias list end tell –Filter selection application bundle only set aRes to filterAliasListByUTI(aliasList, "com.apple.application-bundle") of me set aLen to length of aRes if aLen = 0 then return –Pick up the first element set anApp to contents of first item of aRes set aRes to getBundleIDFromPath(POSIX path of anApp) of me set pListName to aRes & ".plist" set prefPath to POSIX path of (path to preferences) & pListName set aExt to current application’s NSFileManager’s defaultManager()’s fileExistsAtPath:prefPath if aExt = true then revealAFileByFinder(prefPath) of me end if on filterAliasListByUTI(aliasList as list, acceptUTI as string) set fList to {} repeat with i in aliasList set aUTI to getUTIfromPath(i) of me if aUTI is not equal to missing value then set uRes to filterUTIList({aUTI}, acceptUTI) of me if uRes is not equal to {} then set the end of fList to contents of i end if end if end repeat return fList end filterAliasListByUTI –Application path –> Bundle ID on getBundleIDFromPath(aPOSIXpath as string) set aURL to current application’s |NSURL|’s fileURLWithPath:aPOSIXpath set aWorkspace to current application’s NSWorkspace’s sharedWorkspace() set appURL to aWorkspace’s URLForApplicationToOpenURL:aURL set aBundle to current application’s NSBundle’s bundleWithURL:appURL set anID to aBundle’s bundleIdentifier() return anID as string end getBundleIDFromPath on revealAFileByFinder(aPOSIXpath as string) set pathStr to current application’s NSString’s stringWithString:aPOSIXpath set parentPath to pathStr’s stringByDeletingLastPathComponent() set aRes to current application’s NSWorkspace’s sharedWorkspace()’s selectFile:pathStr inFileViewerRootedAtPath:parentPath end revealAFileByFinder –Alias –> UTI on getUTIfromPath(anAlias) set aPOSIXpath to POSIX path of anAlias set aURL to current application’s |NSURL|’s fileURLWithPath:aPOSIXpath if aURL = missing value then return missing value set aRes to aURL’s resourceValuesForKeys:{current application’s NSURLTypeIdentifierKey} |error|:(missing value) if aRes = missing value then return missing value return (aRes’s NSURLTypeIdentifierKey) as string end getUTIfromPath on filterUTIList(aUTIList, aUTIstr) set anArray to NSArray’s arrayWithArray:aUTIList set aPred to NSPredicate’s predicateWithFormat_("SELF UTI-CONFORMS-TO %@", aUTIstr) set bRes to (anArray’s filteredArrayUsingPredicate:aPred) as list return bRes end filterUTIList |
More from my site
(Visited 64 times, 1 visits today)