Posted on 03-16-2016 02:54 AM
Hey AppleScript gurus,
I did intensive researching in the web for the last days but I'm really stuck with that one. Is there any chance to get the "Server" field in the file info pane in Finder?
I tried several AppleScript commands, "file info" for example. This one has the most promising output:
{name:"201601113_PA.pptx", creation date:date "Mittwoch, 13. Januar 2016 um 07:05:05", modification date:date "Mittwoch, 3. Februar 2016 um 09:35:54", size:204378, folder:false, alias:false, package folder:false, visible:true, extension hidden:false, name extension:"pptx", displayed name:"201601113_PA.pptx", default application:alias "Macintosh HD:Applications:Microsoft PowerPoint.app:", kind:"PowerPoint-Präsentation (.pptx)", file type:"", file creator:"", type identifier:"org.openxmlformats.presentationml.presentation", locked:false, busy status:false, short version:"", long version:""}
But unfortunately no "Server" info.
Any hints?
Posted on 03-16-2016 07:11 AM
I'm not 100% sure what you're trying to do.
I'm guessing you're just trying to get the "full path" of a file.
This gets tricky because it's not stored any particular place. I recommend using find.
For example.
If you know it's going to be on an attached volume (but you don't want to search your entire HD) you could do this.sudo find /Volumes ! -path "/Volumes/Macintosh HD" -name Presentation1.pptx
If you're wanting to find it in all locations, I'd recommend assigning it to a variable and reading the variable accordingly.
fileLoc=$(sudo find / -name Presentation1.pptx)
echo "$fileLoc"
Find is kind of tricky to get the hang of, some times.
This might help.
http://www.theunixschool.com/2012/07/find-command-15-examples-to-exclude.html
Posted on 03-16-2016 07:17 AM
@tthurman, I'm trying to get the full server path of a file.
Example: I want the full path of a file the lies on smb://server.domain.com/share/path/to/any/MountPoint/HereLiesMyFile.doc
When I do a "basename HereLiesMyFile.doc" in Terminal, I will get back the POSIX path, e.g. /Volumes/Mountpoint/HereLiesMyFile.doc
But this is not what I want to achieve.
I want the full UNC path where the file is located on the network share, the same UNC path that is displayed in the Finder info window in "Server".
Posted on 03-16-2016 08:15 AM
The only thing I can really find is using df
to get the FileSystem.
You could use sed and awk to move stuff around accordingly.
What I did:
fileLoc=$(find /Volumes ! -path '/Volumes/Macintosh HD' -name Presentation1.pptx)
fileSys=$(df $fileLoc | tail -1 | awk '{print $1}' | sed 's/.*@//g')
That should get the mounted filesystem. Unfortunately, you won't get the type of mount. (smb or afp). Just an idea to help progress.
Hope I could help.
Regards,
TJ
Posted on 03-18-2016 01:27 AM
I was on this point using
dfor
mounttoo. One big problem here is DFS when you can't get the correct share that is mounted. Another problem are special characters (especially the "@") in path names, because this is the only separator you can use to determine the share.
Posted on 01-27-2017 04:25 PM
I have made this Automator service to do it for our users.
Its basically a Bash script that relies on the mount command.
Maybe not the pretties solution but it gets the work done.
#!/bin/bash
_FILE_="$1"
getVolume() {
_VOLUME_=$(echo "$_FILE_" | cut -f1,2,3 -d'/')
}
getProtocol() {
_SHAREINFO_=$(mount | grep "$_VOLUME_")
if [[ $_SHAREINFO_ == *"smbfs"* ]]; then
_PROTOCOL_="SMB"
elif [[ $_SHAREINFO_ == *"afpfs"* ]]; then
_PROTOCOL_="AFP"
else
echo "$_FILE_"
exit 0
fi
}
cutNPaste() {
_SHARE_=$(mount | grep "$_VOLUME_" | cut -d@ -f2- | awk '{ print $1 }')
_PATH_=$(echo "$_FILE_" | sed -- "s|$_VOLUME_||g")
_FULLPATH_="$_SHARE_""$_PATH_"
}
addProtocol() {
if [[ $_PROTOCOL_ == "SMB" ]]; then
echo "smb://$_FULLPATH_"
else
echo "afp://$_FULLPATH_"
fi
}
getVolume
getProtocol
cutNPaste
addProtocol
exit $?
Hope it helps.
One thing to note. It only works on local files and AFP and SMB shares. I've never had to set it up to work on FTP. And I don't have access to a NFS share.
Posted on 10-09-2018 10:58 AM
This bash script looks promising. Any advice on how to account for/replace spaces in the FULLPATH with "%20" so there's hope for a clickable hyperlink?
Posted on 10-09-2018 11:16 AM
#!/bin/bash
url="http://contoso.com/here you go"
url="${url/ /%20}"
echo "$url"
Posted on 10-09-2018 12:54 PM
Thanks, Ryan! However, when I drop that in, it replaces/subs %20 for just the first space that occurs. So when I paste, I get: smb://my.domain.net/Distribution/Internal/Ebook,%20Consignment, and POD reports/2018/08.18/UK Aug 2018.xlsx
Posted on 10-09-2018 01:41 PM
@ndelacretaz This will do it.
#!/bin/bash
url="http://contoso.com/here you go"
url="${url// /%20}"
echo "$url"
Posted on 10-10-2018 04:24 AM
@ryan.ball Excellent! Thanks so much! Cheers...