0
votes

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

1

1 Answers

0
votes

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"