sketchucation logo sketchucation
    • Login
    ℹ️ Licensed Extensions | FredoBatch, ElevationProfile, FredoSketch, LayOps, MatSim and Pic2Shape will require license from Sept 1st More Info

    [Code] Open File Browser and Select File

    Scheduled Pinned Locked Moved Developers' Forum
    5 Posts 3 Posters 280 Views 3 Watching
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • J Offline
      Jim
      last edited by

      This code opens a Windows Exlorer window with the given file selected.

      file = 'C;/Some/Folder/MyFile.rb'
      file.tr!('/', '\\\\')
      system("#{ENV['SystemRoot']}/explorer /n, /select,#{file}")
      
      

      Is there a Mac equivalent?

      Hi

      1 Reply Last reply Reply Quote 0
      • TIGT Offline
        TIG Moderator
        last edited by

        Just opening the file's folder with Sketchup's UI openURL will work cross-platform - PC and MAC... UI.openURL('file:///' + File.dirname(file)) [the file isn't selected though].

        TIG

        1 Reply Last reply Reply Quote 0
        • J Offline
          Jim
          last edited by

          On Windows, calling openURL on a file can execute the file depending on whether the file extension is registered.

          This code just opens the file browser with the given file selected.

          Hi

          1 Reply Last reply Reply Quote 0
          • TIGT Offline
            TIG Moderator
            last edited by

            My code does not open the file, rather it opens the file's folder.
            Using openURL on a folder opens the folder in Windows Explorer...
            However, it doesn't highlight the file in either PC or MAC...

            TIG

            1 Reply Last reply Reply Quote 0
            • D Offline
              driven
              last edited by

              @jim said:

              This code opens a Windows Exlorer window with the given file selected.
              Is there a Mac equivalent?

              Is this what you mean?
              Tig's code does open the file in 'Finder' and highlights the file title
              > file=("/Some/Folder/MyFile.rb") UI.openURL('file:///' + File.dirname(file)) true
              Like this it 'opens' in the associated program for that type of file. i.e. TextWrangler opens ruby files on my system.
              > file=("/Some/Folder/MyFile.rb") UI.openURL('file:///' + (file)) true
              This will also open in 'Finder'
              > file = './Some/Folder/MyFile.rb' system("open -R #{file}") true note: returns true/false

              > file = './Some/Folder/MyFile.rb' system %(open -R #{file}) true note: also returns true/false

              shorthand works as well
              >open -R './Some/Folder/MyFile.rb'`` note: NO return of true/false

              Without the -R recursive flag it will 'open' in the associated app

              Again, it can be with or without the return, dependant on the call syntax.

              john

              learn from the mistakes of others, you may not live long enough to make them all yourself...

              1 Reply Last reply Reply Quote 0
              • 1 / 1
              • First post
                Last post
              Buy SketchPlus
              Buy SUbD
              Buy WrapR
              Buy eBook
              Buy Modelur
              Buy Vertex Tools
              Buy SketchCuisine
              Buy FormFonts

              Advertisement