This code example displays the "Get Info" window for a specified file (successfully tested with Snow Leopard and Yosemite):kenmo wrote:(b) display the "Get Info" window about a file
Code: Select all
EnableExplicit
ImportC ""
NSPerformService(*ItemName, *NSPasteboard)
EndImport
Define Pasteboard.I
Define TargetFile.S = #PB_Compiler_Home + "logo.png"
Define TypeArray.I
; ----- Create Pasteboard
Pasteboard = CocoaMessage(0, 0, "NSPasteboard pasteboardWithUniqueName")
If Pasteboard
TypeArray = CocoaMessage(0, 0,
"NSArray arrayWithObject:$", @"NSStringPboardType")
If TypeArray
CocoaMessage(0, Pasteboard,
"declareTypes:", TypeArray,
"owner:", 0)
If CocoaMessage(0, Pasteboard,
"setString:$", @TargetFile,
"forType:$", @"NSStringPboardType") = #YES
; ----- Show info for selected file
NSPerformService(CocoaMessage(0, 0,
"NSString stringWithString:$", @"Finder/Show Info"), Pasteboard)
EndIf
EndIf
EndIf
Code: Select all
EnableExplicit
ImportC ""
NSPerformService(*ItemName, *NSPasteboard)
EndImport
Define Pasteboard.I
Define TargetFile.S = #PB_Compiler_Home + "logo.png"
Define TypeArray.I
Define Workspace.I = CocoaMessage(0, 0, "NSWorkspace sharedWorkspace")
If Workspace
; ----- Open Finder and select target file
CocoaMessage(0, Workspace,
"selectFile:$", @TargetFile,
"inFileViewerRootedAtPath:$", @"")
; ----- Create Pasteboard
Pasteboard = CocoaMessage(0, 0, "NSPasteboard pasteboardWithUniqueName")
If Pasteboard
TypeArray = CocoaMessage(0, 0,
"NSArray arrayWithObject:$", @"NSStringPboardType")
If TypeArray
CocoaMessage(0, Pasteboard,
"declareTypes:", TypeArray,
"owner:", 0)
If CocoaMessage(0, Pasteboard,
"setString:$", @TargetFile,
"forType:$", @"NSStringPboardType") = #YES
; ----- Show info for selected file
NSPerformService(CocoaMessage(0, 0,
"NSString stringWithString:$", @"Finder/Show Info"), Pasteboard)
EndIf
EndIf
EndIf
EndIf