0

I recorded a macro to save a workbook to the desktop on a Mac, but I can't figure out how to make the username a variable name similar to VBA environ$(username)

ActiveWorkbook.SaveAs Filename:="/Users/username/Desktop/test.xls", _

FileFormat:=xlExcel8, Password:="", WriteResPassword:="", _ ReadOnlyRecommended:=False, CreateBackup:=False

tmill
  • 1
  • 1
  • possible duplicate https://stackoverflow.com/questions/1104972/how-do-i-get-the-name-of-the-active-user-via-the-command-line-in-os-x – endo.anaconda Sep 23 '17 at 20:13
  • Possible duplicate of [How do I get the name of the active user via the command line in OS X?](https://stackoverflow.com/questions/1104972/how-do-i-get-the-name-of-the-active-user-via-the-command-line-in-os-x) – endo.anaconda Sep 23 '17 at 20:13

1 Answers1

0

In AppleScript you can set a variable, e.g. theFilename to the path of the users Desktop and the filename as, e.g.:

set theFilename to POSIX path of (path to desktop as string) & "filename.xls"

Have look at AppleScript documentation for path to (folder), for all of the various locations this form is applicable.

If it's just the users name you want:

set theShortUserName to short user name of (get system info)

Or

set theShortUserName to do shell script "printf $USER"
user3439894
  • 7,266
  • 3
  • 17
  • 28