hi
i’m trying to make an applescript that will work generically on all apple computers. i need to refer to the desktop but to do this you need to know the desktop for example
tell app “finder”
open folder “Macintosh HD: Users: Yourusername : desktop”
end tell
so is there a way of refering to the users desktop folder without knowing their username or is their a script which can find their username
Well, I’m quite new to AppleScript, but I’ve been doing a lot of research this morning on syntax, etc. I keep coming across the following way of referencing a folder:
tell application "Finder" to count every file in folder "Desktop" in home
No need to know the username here. Maybe it will work for you?
The Finder has its own ‘desktop’ keyword to refer to the current user’s desktop.
tell application "Finder"
open desktop
end tell
You can also get an alias or a text path to the desktop without using the Finder:
set desktopFolder to (path to desktop) -- returns an alias
-- or:
set desktopPath to (path to desktop as Unicode text) -- returns the path as Unicode text
just another way to do it. this finds all users on an OS X computer and puts a file on the Desktop of each user:
set getUsers to (do shell script "/usr/bin/nireport / /users name uid | grep \"5[0-9][0-9]\"")
set howMany to number of paragraphs in getUsers
set theUsers to {missing value}
set i to 1
repeat while i ≤ howMany
if i = 1 then
set theUsers to word 1 of paragraph i of getUsers as list
else
set theUsers to (theUsers & word 1 of paragraph i of getUsers)
end if
set i to (i + 1)
end repeat
set x to 1
repeat while x ≤ howMany
do shell script "/usr/bin/touch /Users/" & item x of theUsers & "/Desktop/testfile.txt" with administrator privileges
set x to (x + 1)
end repeat