Any chance to get the "Server" field in File info?

m_entholzner
Contributor III

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? 2cb8a765c28a46e787ca10e34999ba8c

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?

10 REPLIES 10

tthurman
Contributor III

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

m_entholzner
Contributor III

@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".

tthurman
Contributor III

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

m_entholzner
Contributor III

I was on this point using

df
or
mount
too. 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.

macninja_IO
New Contributor III

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.
9c5273299ba7406cb6d77945d02b9b45
57655b0328134ad9aae40b3226e82889

#!/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.

ndelacretaz
New Contributor II

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?

ryan_ball
Valued Contributor

@ndelacretaz

#!/bin/bash
url="http://contoso.com/here you go"
url="${url/ /%20}"
echo "$url"

ndelacretaz
New Contributor II

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

ryan_ball
Valued Contributor

@ndelacretaz This will do it.

#!/bin/bash
url="http://contoso.com/here you go"
url="${url// /%20}"
echo "$url"

ndelacretaz
New Contributor II

@ryan.ball Excellent! Thanks so much! Cheers...