Execute "Get Info" on a file from Xojo

Hi,

I’m searching a way to Execute “Get Info” on a file from Xojo, to get the same window you get from the finder.

Shell, Applescript, MBS ?

Thanks,
Fred

In Applescript:

set f to alias "path:to:file"
tell app "Finder"
  open information window of f
end tell

Thanks Kem.

How do I call it in Xojo , please ?

https://forum.xojo.com/3070-running-applescripts/0

Thanks Jeff, I tried it, but it is not working anymore.

I added the Kem ’ script in my project, how do I pass f ?

Thanks,

In AppleScript

on run(path)
	set f to POSIX file path as alias
	log f
	tell application "Finder"
		open information window of f
	end tell
end 

save as a script - name it “ShowInfo.scpt”
drag into your project

to run it

   ShowInfo( NATIVE PATH TO THE FILE YOU WANT THE INFO FOR )

something like

      dim f as folderitem = GetOpenFolderItem("")
      ShowInfo ( f.NativePath )

Great !

Thanks Norman

Up until now, I shelled out to osascript.
This way seems pretty cool but somehow I’m unable to start an AppleScript it in it’s own thread. It freezes everything. Even when started from a thread.
Is this a known limitation?

Just a little note: If you try to use this in an application for the Mac App Store; you’ll be instantly rejected. Apple do not permit scripting of the “Finder”. If you don’t care about the App Store, no need to worry.

I’m not aware of any API to pragmatically display this dialog either.

@Marco Hof : I’m not seeing this and I use AppleScript EVERYWHERE in my app. But I’m using NSAppleScriptMBS.

Hi Sam,

Maybe a way to do it without Applescript here and in sandboxed App :

http://stackoverflow.com/questions/10048060/how-to-open-file-directory-get-info-window

Bur I don’t know how to code i in Xojo…

Fred

Indeed, good find Fred.

Providing an application has a NSService, the following code could be adapted to fill the oncoming void that Apple Script’s removal will leave.

This code is using current APIs (as of the date of writing) and has been tested on 32-Bit & 64-Bit (the code on stackoverflow uses outdated API).

Simply pass it an array of folderitems or if you only want to show one, wrap it in a array function.

showFileInfo( array( f ) )

[code]Sub showFileInfo(files() as folderItem)
#if TargetCocoa then
declare function NSClassFromString lib “Cocoa” ( aClassName as CFStringRef ) as ptr

// --- Create an array of NSURLS.
declare function arrayWithCapacity lib "Cocoa" selector "arrayWithCapacity:" ( NSMutableArrayClassREf as ptr, capacity as integer ) as ptr
declare sub addObject lib "Cocoa" selector "addObject:" ( NSArrayID as Ptr, NSObjectID as Ptr )
declare function fileURLWithPath lib "Cocoa" selector "fileURLWithPath:isDirectory:" ( NSURLClassRef as Ptr, path as CFStringRef, isDirectory as boolean ) as ptr

Dim fileList as Ptr = arrayWithCapacity( NSClassFromString( "NSMutableArray" ), ubound( files ) )
for each item as folderitem in files
  addObject( fileList, fileURLWithPath( NSCLassFromString( "NSURL" ), item.nativePath, item.directory ) )
next

// --- Now we need to create a NSPasteboard with our NSArray of NSURLs.
declare function pasteboardWithUniqueName lib "Cocoa" selector "pasteboardWithUniqueName" ( NSPasteboardClassRef as ptr ) as Ptr
declare function writeObjects lib "Cocoa" selector "writeObjects:" ( NSPasteBoardID as ptr, NSArrayID as Ptr ) as boolean

Dim pBoard as Ptr = pasteboardWithUniqueName( NSClassFromString( "NSPasteboard" ) )

if writeObjects( pBoard, fileList ) = false then
  msgBox "Failed to add items to the pasteboard instance"
  return
end if

// --- Lastly we call the NSService with the NSPasteboard.
declare function NSPerformService lib "Cocoa" ( itemname as CFStringRef, NSPasteboard as ptr ) as boolean
if NSPerformService( "Finder/Show Info", pBoard ) = false then msgBox "Failed to perform service"

#endif
End Sub
[/code]

Great coding , Sam !!!

Many thanks, this will avoid using AppleScript in case one wants to send his app to the Mac App Store .