Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

DennisBlah

macrumors 6502
Original poster
Dec 5, 2013
485
2
The Netherlands
Is it possible to retrieve the author name of an excel file, without actually opening the file ?

Code:
set thePath to (path to desktop as Unicode text) & "test.xlsx"
get info for thePath as alias

Is not really what I'm looking for.
I want to retrieve the real Author which you can find in excel underneath:
File->Properties : Author
 
Hi,

There's a user name that appears in the meta data if you use 'mdls'. For example:

do shell script "mdls /path/to.your/file.xls"

…I'm not sure whether that corresponds to what you see in Excel though. Might be worth you doing some testing to see.

Rob
 
Hello superscape, thanks for your reply. I have seen multiple things about mdls /path/to/file.extension

But this always results me in into:
Code:
/Users/Dennis/Desktop/test.xlsx: could not find /Users/Dennis/Desktop/test.xlsx.

Which I am really really REALLY sure it does exists and it is on this location.
 
Is it possible to retrieve the author name of an excel file, without actually opening the file ?

It does look like the item you're after is in there under kMDItemAuthors, value is returned in paragraph 2 of the mdls query, and yes there's no need to open the file (its last opened date wont change).

Following should do what you're after (I've structured it to get all the words in para 2 rather than assuming folks always have a two word name).

Code:
set excelName to quoted form of POSIX path of (choose file)

set mdlsResult to paragraph 2 of (do shell script "mdls " & excelName)

set authorName to text (word 1) thru (word (count words of mdlsResult)) of mdlsResult

return authorName

ps is also good for Word PDF files etc
 
Last edited:
You can also go straight after what you're looking for with something like this :

Code:
set excelName to quoted form of POSIX path of (choose file)
set authorName to (do shell script "mdls -name kMDItemAuthors  -raw " & excelName & " | awk -F'\"' '{ getline; print $2; exit }'")
 
aye, or possibly go one stage further and reduce it to

Code:
set authorName to (do shell script "mdls -name kMDItemAuthors  -raw " & (quoted form of POSIX path of (choose file)) & " | awk -F'\"' '{ getline; print $2; exit }'")
 
You guys are amazing.
However, with all these samples, I also get the error that the file is not been found.

Did I noted that I'm running 10.9.2 ?
 
However, with all these samples, I also get the error that the file is not been found.

Then you need to start with the simplest thing, find out if it works, and work up from that.

Script 1:
Code:
set chosen to (choose file)
What does this produce as a result when run in AppleScript Editor?
Post the actual results, copied and pasted from the actual results window.

Script 2:
Code:
set chosen to (choose file)
get info for chosen
Same questions here. Post the actual results.

Script 3:
Code:
set chosen to (choose file)
set pathname to Posix path of chosen
Post the results.

Script 4:
Code:
set chosen to (choose file)
set pathname to quoted form of (Posix path of chosen)
Choose a file with a space in its name. Post the results.

Script 5:
Code:
set chosen to (choose file)
set pathname to quoted form of (Posix path of chosen)
set ls_info to do shell script "ls -ld " & pathname
Choose a file with a space in its name. Post the results.


Test the scripts in the order given. Post the actual results. Report any errors, posting the complete text of the actual error message.
 
Then you need to start with the simplest thing, find out if it works, and work up from that.
...
Test the scripts in the order given. Post the actual results. Report any errors, posting the complete text of the actual error message.

Sorry for this late reply, I been really busy with a huge project over here.

This ls -ld part of yours works well, unfortunally it's not getting the actual author of the excel file. I can retrieve this by opening the file and go through the menu's and stuff. But this is something I don't want to do, as I'm working on an 'robot' that has to determine if this file is authorized to be imported in our database. If so, then we get the actual content.

Because I'm talking about 1000+ files a day, I don't want to have to open them fysically for determining the owner.

I must be making my excuses to all of you guys. For some reason on my iMac mdls will never find any files from my desktop, however on my macbook it does. (I just tried it on my macbook)

Again my excuse for this, I have experienced some more stupid trouble with this iMac. Thanks for all your help guys!
 
I am a developer of Excel barcode addin.As for your question,i'd like to share some Excel tips with you,i hope it will help.
The username that a person sets in Excel when first installing the software or when changing the general options for the program cannot be accessed via formula. Instead, you need to use a macro to access the information and then make it available to your worksheet. This is possible through the use of a user-defined function. Consider the following simple example:

Code:
Function GetUserName()
    GetUserName = Application.UserName
End Function
Note that the macro does nothing more than to access the UserName property of the Application object. You use this function in your worksheet in the following manner:
Code:
=GetUserName()
With this simple formula in a cell, the username is displayed in the cell.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.