I have a code:
func openGetInfoWnd(for urls: [URL]) {
let pBoard = NSPasteboard(name: NSPasteboard.Name(rawValue: "pasteBoard_\(UUID().uuidString )") )
pBoard.writeObjects(urls as [NSPasteboardWriting])
NSPerformService("Finder/Show Info", pBoard)
}
this code opens multiple windows of Finder's "Get Info"
like it displays on Cmd + I hotkey
How can I open single one window ("Show Inspector" / "Get Info" / "Multiple Item Info") for multiple local urls?
Like it displayed on Cmd + Option + I press in Finder
PS: code: NSPerformService("Finder/Show Inspector", pBoard)
ofc does not work :)
Tried many ways, you are right, NSPerformService is very limited, and cannot achieve it. And I also tried Apple Script's approach
:
tell application "Finder" to open information window of file aFile
But that only works for the single file and there is no open "multiple information window" thing in Finder.
Luckily, your keyboard shortcuts remind me that I can simulate the file selection and keyboard keydown events.
So I believe below apple script can help you:
set fileList to {POSIX file "/Users/0x67/Downloads/new.html", POSIX file "/Users/0x67/Pictures/tt/00003-771884301.png"}
tell application "Finder"
activate
set selection to fileList
tell application "System Events"
keystroke "i" using {command down, option down}
end tell
end tell
I think you can call this create this apple script in Swift and call it.
Here is a useful link to call it in swift: