Applescript variable user and drive
I'm using Script Editor to make a script which, when run, will delete certain files related to an app (cache and preference files mainly). I have successfully managed to get this to run on my Mac with the following:
tell application "Finder"
delete ("Macintosh HD:Users:pops:Library:LaunchAgents:com.skype.skype.shareagent.plist")
end tell
However, I want to be able to run this script, which I'm exporting as an app out of Script Editor, on any Mac so my question is, what do I replace pops with to make it work in any user account? Similarly, what would I replace Macintosh HD with in the situation where the user has renamed their drive?
I have tried adding:
tell application "System Events"
set UserName to name of current user
end tell
at the start and have replaced pops with UserName but it didn't work.
The list of files I'm instructing it to delete may not all be on the Mac either so is there also a way to stop the Handler can’t handle objects of this class error message popping up and worrying the user when run?
Thank you :)
MacBook Pro 15", macOS 10.14