[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}") truenote: returns true/false> file = './Some/Folder/MyFile.rb' system %(open -R #{file}) truenote: 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
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better π
Register LoginAdvertisement