• Login
sketchucation logo sketchucation
  • Login
🤑 SketchPlus 1.3 | 44 Tools for $15 until June 20th Buy Now

[Code] Open File Browser and Select File

Scheduled Pinned Locked Moved Developers' Forum
5 Posts 3 Posters 278 Views
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 8 Sept 2012, 13:32

    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
    • T Offline
      TIG Moderator
      last edited by 8 Sept 2012, 14:47

      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 8 Sept 2012, 15:04

        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
        • T Offline
          TIG Moderator
          last edited by 8 Sept 2012, 15:07

          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 11 Sept 2012, 11:47

            @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
            1 / 1
            • First post
              4/5
              Last post
            Buy SketchPlus
            Buy SUbD
            Buy WrapR
            Buy eBook
            Buy Modelur
            Buy Vertex Tools
            Buy SketchCuisine
            Buy FormFonts

            Advertisement