How to show a file on disk ?

  1. 4 months ago

    Jean-Yves P

    Jul 11 Pre-Release Testers, Xojo Pro Europe (France, Besançon)

    thought it should be simple, but it seems not.
    I have a folderitem, and I want to show the file on the disk (not open it, only show it)
    should ideally work on mac,linux or win

    any hint ?
    thanks.

    just found this ... https://forum.xojo.com/16010-reveal-file-in-explorer

    ps: had to use google to find it, it did not show up with xojo forum search ...

  2. Emile S

    Jul 11 Europe (France, Strasbourg)

    Afficher le fichier: non. Afficher le dossier contenant le fichier oui.

    Désolé / sorry.

  3. Jean-Yves P

    Jul 11 Pre-Release Testers, Xojo Pro Answer Europe (France, Besançon)
    Edited 4 months ago

    just found this ... https://forum.xojo.com/16010-reveal-file-in-explorer

    ps: had to use google to find it, it did not show up with xojo forum search ...

  4. Emile S

    Jul 12 Europe (France, Strasbourg)

    Was you able to implement one of the given advices ?

  5. Christian S

    Jul 12 Pre-Release Testers, Xojo Pro, XDC Speakers Germany

    Or use NSWorkspaceMBS .selectFile(file as folderitem) as boolean in MBS Plugin for Mac:

    dim f as FolderItem
    
    f=SpecialFolder.Desktop.Child("test.txt")
    
    if NSWorkspaceMBS.selectFile(f) then
      MsgBox "Ok"
    else
      MsgBox "failed"
    end if

    for Windows, you can use WindowsShellExecuteMBS :

    dim e as Integer
    dim f as FolderItem
    
    // show documents folder
    
    f = SpecialFolder.Documents
    e = WindowsShellExecuteMBS(0, "explore", f.AbsolutePath, "", "", 10)
  6. Jean-Yves P

    Jul 12 Pre-Release Testers, Xojo Pro Europe (France, Besançon)
    Edited 4 months ago

    @Emile S Was you able to implement one of the given advices ?

    yes norman post is working for me (I only tested on macos but it seems consistent with other posts and threads )
    for macos it uses applescript. hope Apple will not abandon it too soon !
    anyway we have some shell equivalent if .

    Public Sub ShowFileOnDisk(f as folderitem)
      If f is nil or not f.Exists then
        Return
      end if
      #if TargetMacOS
        dim a as AppleEvent = NewAppleEvent("misc", "slct", "MACS") 
        a.FolderItemParam("----") = f 
        If a.send then
          a = NewAppleEvent("misc", "actv", "MACS") 
          If a.send then 
            //success 
          Else
            //activate failed 
          End if 
        Else //select failed 
        End if
      #ElseIf TargetWindows
        dim s as new shell
        s.execute("explorer.exe /select, "+chr(34)+f.shellpath+chr(34))
      #elseif TargetLinux
        // Use xdg-open which is desktop-independent, and should be available in most newer distros
        // Otherwise fallback on the two major desktop dependent command tools
        Dim sh As New Shell
        Dim commandTools() As String = Array( "xdg-open", "gnome-open", "kde-open" )
        
        For Each tool As String In commandTools
          sh.Execute( "which " + tool )
          If Left( sh.Result, 1 ) = "/" Then
            sh.Execute( tool + " " + f.Parent.ShellPath )
            Exit
          End If
        Next
      #endif
    End Sub
  7. Jean-Yves P

    Jul 12 Pre-Release Testers, Xojo Pro Europe (France, Besançon)

    @ChristianSchmitz Or use NSWorkspaceMBS .selectFile(file as folderitem) as boolean in MBS Plugin for Mac:

    dim f as FolderItem
    
    f=SpecialFolder.Desktop.Child("test.txt")
    
    if NSWorkspaceMBS.selectFile(f) then
      MsgBox "Ok"
    else
      MsgBox "failed"
    end if

    for Windows, you can use WindowsShellExecuteMBS :

    dim e as Integer dim f as FolderItem // show documents folder f = SpecialFolder.Documents e = WindowsShellExecuteMBS(0, "explore", f.AbsolutePath, "", "", 10)

    sorry Christian, I'm really a fan of "don't do it with a plugin when you can do it without" !

  8. Emile S

    Jul 12 Europe (France, Strasbourg)

    Works fine here on El Capitan. Thanks.

  9. Thomas R

    Jul 12 Europe, France, Besancon
    Edited 4 months ago

    I get this Function here, I will search in which post after :
    Public Sub RevealEltFinder(CetElt as FolderItem)

      #If TargetMacOS Then
        Declare Function objc_getClass Lib "libobjc.dylib" ( name as CString ) as ptr
        Declare Function sharedWorkspace Lib "AppKit" selector "sharedWorkspace" ( obj As ptr ) as ptr
        Declare Function selectFile Lib "AppKit" selector "selectFile:inFileViewerRootedAtPath:" ( obj as ptr, fPath as CFStringRef, rootFullPath as CFStringRef ) as Boolean
        Dim workspace as ptr = sharedWorkspace( objc_getClass( "NSWorkspace" ) )
        ' assert ( workspace <> nil, CurrentMethodName + " is Nil")
        Call selectFile( workspace, CetElt.NativePath, "")
        
        ' Autre méthode via Cde Shell :
        ' Dim CdeShell as New Shell
        ' CdeShell.Execute "open -R " + CetElt.ShellPath
        ' TampNbre = CdeShell.ErrorCode
        ' TampText = CdeShell.Result
        ' CdeShell.Close
        
        ' Ancienne méthode via AppleScript :
        ' CetElt.Parent.Launch ' Launch le dossier parent donc l'ouvre dans le Finder, et ne place que cette fenêtre au 1er plan, pas toutes celles du Finder comme
        '  Activate d'AppleScript. Mais le Reveal d'AppleScript ci-dessous ne fait qu'ouvrir la fenêtre du dossier, ça ne la place pas au 1er plan
        ' RevealThisItem(CetElt.NativePath) ' .ShellPath_fAS) ' Mieux que ci-dessus, en plus d'ouvrir la fenêtre du dossier, ça sélectionne l'élément dans la fenêtre, n'existe pas dans RealBasicEn
        
      #Else ' Windows ou Linux
        CetElt.Parent.Launch ' Launch le dossier parent donc l'ouvre dans le Finder
        
      #EndIf



    Edit : I copy it from this forum .

or Sign Up to reply!