How to reveal path to a file/folder
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
How to reveal path to a file/folder
I wonder if there is a way, given a path, to show the location of a file/folder on OSX and Windows.
Similar to what the system does with aliases, opening a window with the selected file/folder.
I could do it with Applescript, but I would like a solution for both platforms (may be using a shell command?).
Thanks for any help.
Trevix
Similar to what the system does with aliases, opening a window with the selected file/folder.
I could do it with Applescript, but I would like a solution for both platforms (may be using a shell command?).
Thanks for any help.
Trevix
Last edited by trevix on Fri Mar 02, 2018 4:16 pm, edited 1 time in total.
Trevix
OSX 14.3.1 xCode 15 LC 10 DP7 iOS 15> Android 7>
OSX 14.3.1 xCode 15 LC 10 DP7 iOS 15> Android 7>
-
- VIP Livecode Opensource Backer
- Posts: 9648
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: How to display path to a file/folder
Hi.
But if you already have a path ("...given a path..."), either because you just do or you obtain it with the "answer file" or "ask file" commands, don't you already know its "location", as you put it?
Craig Newman
But if you already have a path ("...given a path..."), either because you just do or you obtain it with the "answer file" or "ask file" commands, don't you already know its "location", as you put it?
Craig Newman
Re: How to display path to a file/folder
I was not clear enough:
I have a list of file paths and I would like, upon clicking on a path, to have the Finder (on OSX) or Windows to open the window where the file is and select the file
I have a list of file paths and I would like, upon clicking on a path, to have the Finder (on OSX) or Windows to open the window where the file is and select the file
Trevix
OSX 14.3.1 xCode 15 LC 10 DP7 iOS 15> Android 7>
OSX 14.3.1 xCode 15 LC 10 DP7 iOS 15> Android 7>
-
- VIP Livecode Opensource Backer
- Posts: 7228
- Joined: Sat Apr 08, 2006 8:31 pm
- Location: Minneapolis MN
- Contact:
Re: How to display path to a file/folder
This little trick works on Mac and (probably) Windows:
Even though you've got a folder path, the "file" designation will open the folder. I don't know of a way to actually select the file, but the user will be in the right place.
Code: Select all
put <path/to/folder/" into tFolder
launch url ("file:" & tFolder)
if the result <> "" then answer the result -- error check here
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
HyperActive Software | http://www.hyperactivesw.com
Re: How to display path to a file/folder
This thread may have some cross platform possible investigations to explore
http://forums.livecode.com/viewtopic.php?f=9&t=20058
http://forums.livecode.com/viewtopic.php?f=9&t=20058
-
- VIP Livecode Opensource Backer
- Posts: 2262
- Joined: Thu Feb 28, 2013 11:52 pm
- Location: Göttingen, DE
Re: How to display path to a file/folder
Nothing new but collects all hints from above in a cross-platform working script.
I have it in nearly all my newer stacks, mostly in a 8x8 square button at topleft.
Works with LC 6/7/8/9 on Mac/Win/Linux(all flavours I use)/Raspi.
It opens a selected folder of the path containing the file, alike clicking at top midth of an open window in most text editors.
I have it in nearly all my newer stacks, mostly in a 8x8 square button at topleft.
Works with LC 6/7/8/9 on Mac/Win/Linux(all flavours I use)/Raspi.
It opens a selected folder of the path containing the file, alike clicking at top midth of an open window in most text editors.
Code: Select all
on mouseDown
put the long id of this stack into M #<-- this is an example of a path
set itemdelimiter to quote
put item -1 of M into M
set itemdelimiter to comma
replace "/" with CR in M
if line 1 of M is empty then put "[Top]" into line 1 of M
if line 2 of M is empty then
put "[]"& line 3 of M into line 1 to 3 of M
end if
put "(" before last line of M
put M into me
end mouseDown
on mouseUp
end mouseUp
on mouseRelease
end mouseRelease
on menuPick
goTo line 1 to (the menuhistory of me) of me -- in script of grp "stackPath"
end menuPick
on mouseEnter
set tooltip of me to "Select from the path to this stack."
end mouseENter
on goTo t
set itemdelimiter to "]"
put item 1 of line 1 of t into t1
if colon is in t1 then -- do nothing
else if "[Top" is t1 then put empty into line 1 of t
else if "[" is t1 then put "//" into char 1 to 2 of t
else put CR before t
set itemdelimiter to comma
if t is empty then put CR into t
replace CR with "/" in t
if the platform is "linux" then
try
launch document t
get shell("xdg-open " & quote&t"e)
end try
else launch document t
end goTo
Last edited by [-hh] on Fri Mar 02, 2018 4:33 pm, edited 1 time in total.
shiftLock happens
Re: How to display path to a file/folder
I give up. I think I am going to look for Applescript/VBscript solutions.
This works pretty good for OSX (replacing <ThePath> with a regular path to folder or files:
It confuses itself a little bit if you need to locate an app (Something.app), but I can go with it.
Googling for VBscript or Shell I found this:
https://stackoverflow.com/questions/136 ... e-selected
Not sure how to use it.
This works pretty good for OSX (replacing <ThePath> with a regular path to folder or files:
Code: Select all
tell application "Finder"
activate
try
reveal (POSIX file "<ThePath>")
on error
return "error"
end try
end tell
Googling for VBscript or Shell I found this:
https://stackoverflow.com/questions/136 ... e-selected
Not sure how to use it.
Trevix
OSX 14.3.1 xCode 15 LC 10 DP7 iOS 15> Android 7>
OSX 14.3.1 xCode 15 LC 10 DP7 iOS 15> Android 7>
-
- VIP Livecode Opensource Backer
- Posts: 2262
- Joined: Thu Feb 28, 2013 11:52 pm
- Location: Göttingen, DE
Re: How to display path to a file/folder
[It's hard to understand what you want with that title. Please change "display" to "reveal".]
The following script reveals a file in the Finder/Desktop manager, that is it opens the containing folder and selects the file icon (or the file name in a list).
Works on Mac/Win/linux/Raspi.
The following script reveals a file in the Finder/Desktop manager, that is it opens the containing folder and selects the file icon (or the file name in a list).
Works on Mac/Win/linux/Raspi.
Code: Select all
-- Some file path examples (on windows LC uses slash).
local f="/Users/admin/Documents/Spenden\ für\ Freies\ Wissen\ -\ Wikimedia\ Fördergesellschaft.pdf" -- Mac
local g="C:/Users/IEUser/Documents/minimal/stars1.png" -- Win
local h="/home/hh/Documents/blendDemoLinux.livecode" -- linux
on mouseUp
switch the platform
case "MacOS"
get shell("open -R " & f)
break
case "Win32"
set the hideConsoleWindows to true
replace "/" with "\" in g
get shell("explorer.exe /select, " & g)
break
case "linux"
-- nautilus or nemo may not yet be installed
-- get shell("nemo " & h) -- some use "nemo" instead of nautilus
get shell("nautilus " & h)
break
end switch
end mouseUp
shiftLock happens
Re: How to reveal path to a file/folder
Thanks for the help.
I tried on OSX Sierra and LC 8.1.9 but it does not works.
Given a path:
I think it has do do with the "space" on the path, but I cannot avoid of having it.
Regards
Trevix
I tried on OSX Sierra and LC 8.1.9 but it does not works.
Given a path:
the it var is set to:/Users/trevix/Documents/AAA_LavoriInCorso/Piccolo Installer/Test_Files/License.txt
I copied the path from the info of the files and I am sure is correct.The files /Users/trevix/Documents/AAA_LavoriInCorso/Piccolo and /Users/trevix/Library/Preferences/Piccolo_Installer_Preferences/Installer/Test_Files/License.txt do not exist.
I think it has do do with the "space" on the path, but I cannot avoid of having it.
Regards
Trevix
Trevix
OSX 14.3.1 xCode 15 LC 10 DP7 iOS 15> Android 7>
OSX 14.3.1 xCode 15 LC 10 DP7 iOS 15> Android 7>
Re: How to reveal path to a file/folder
Maybe enclose the path in single quotes, i.e. (psuedo)
set the path to "'" & the path & "'"
set the path to "'" & the path & "'"
Re: How to reveal path to a file/folder
Perfect !!
Thanks
Thanks
Trevix
OSX 14.3.1 xCode 15 LC 10 DP7 iOS 15> Android 7>
OSX 14.3.1 xCode 15 LC 10 DP7 iOS 15> Android 7>
-
- VIP Livecode Opensource Backer
- Posts: 2262
- Joined: Thu Feb 28, 2013 11:52 pm
- Location: Göttingen, DE
Re: How to reveal path to a file/folder
Either use single quotes around the original file name, as bogs said, or use NO quotes and escape space like in my path example for Mac above.
Sadly revealing several files in the same folder doesn't work as above. If the folder is already open then simply the selection changes.
Opening several windows for files in different folders works.
(Opening a new window for each call targeting the same folder could also conflict with general user settings).
Code: Select all
function sq t
return "'"& t &"'"
end sq
function sp t
replace space with "\ " in t
return t
end spc
Opening several windows for files in different folders works.
(Opening a new window for each call targeting the same folder could also conflict with general user settings).
shiftLock happens
Re: How to reveal path to a file/folder
Happy to help trevix
Re: How to reveal path to a file/folder
Thanks very much for your help -hh.
I want to notice also that, on OSX, what happens running the script is slightly different if the path file is a document (yyy.txt) or an app (xxx.app).
It is as if the system does not know if to consider it a file or a folder (being a package).
Not a problem, tough.
I want to notice also that, on OSX, what happens running the script is slightly different if the path file is a document (yyy.txt) or an app (xxx.app).
It is as if the system does not know if to consider it a file or a folder (being a package).
Not a problem, tough.
Trevix
OSX 14.3.1 xCode 15 LC 10 DP7 iOS 15> Android 7>
OSX 14.3.1 xCode 15 LC 10 DP7 iOS 15> Android 7>
-
- VIP Livecode Opensource Backer
- Posts: 2262
- Joined: Thu Feb 28, 2013 11:52 pm
- Location: Göttingen, DE
Re: How to reveal path to a file/folder
My script above selects not only files but also folders in their containing folder.
On MacOS an application (package) is actually a folder.
You could just select what you need in your scenario.
This opens the Application folder and selects (the "folder") TextEdit.app:
And this opens the contents folder and selects the binary file:
get shell ("open /Applications/TextEdit.app")
launches TextEdit,
get shell ("open -n /Applications/TextEdit.app")
launches a new instance of TextEdit,
get shell ("open /Applications/TextEdit.app/Contents/MacOS/TextEdit")
launches Terminal (because it is a unix binary) which in turn launches TextEdit.
On MacOS an application (package) is actually a folder.
You could just select what you need in your scenario.
This opens the Application folder and selects (the "folder") TextEdit.app:
Code: Select all
get shell ("open -R /Applications/TextEdit.app")
Code: Select all
get shell ("open -R /Applications/TextEdit.app/Contents/MacOS/TextEdit")
launches TextEdit,
get shell ("open -n /Applications/TextEdit.app")
launches a new instance of TextEdit,
get shell ("open /Applications/TextEdit.app/Contents/MacOS/TextEdit")
launches Terminal (because it is a unix binary) which in turn launches TextEdit.
shiftLock happens