[Code] Open File Browser and Select File
-
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?
-
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]. -
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.
-
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... -
@jim said:
This code opens a Windows Exlorer window with the given file selected.
Is there a Mac equivalent?
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/falseshorthand works as well
>
open -R './Some/Folder/MyFile.rb'`` note: NO return of true/falseWithout 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
Advertisement