Desktop cleanup - launch at shutdown

Hi Everyone,

I want a script that will help reduce desktop clutter:

1 - User tries to shut down their machine
2 - Script automatically launches, dialog box comes up “Move contents of desktop to today’s folder?”
3 - If “Ok”, all items go into folder, named by today’s date
4 - Computer shuts down

As I have been looking around this site for help, it seems like maybe this requires something more complicated than just AS? Do I need to do GUI or something?

Thanks for your help!
Clobberella

This doesn’t ask permission, but you can alter it to suit your needs:

tell application "Finder"
	set today to short date string of (current date)
	set mydocuments to path to documents folder as alias
	set mydesktop to path to desktop folder as alias
	set thedesktop to "Desktop "
	set thename to thedesktop & today
	if not (exists folder (thename) in mydocuments) then
		set thehome to (make new folder at mydocuments with properties {name:thename}) as alias
		open folder thehome
	else
		set thehome to ((mydocuments as text) & thename) as alias
	end if
	set everyfile to every file in mydesktop
	set everyfolder to every folder in mydesktop
	move everyfile to folder thehome
	move everyfolder to folder thehome
end tell

Hey cwtnospam, this is great! More than I was expecting. Thanks for sharing!

Has anyone had success getting a script to activate at Shut Down?

Hi,

take a look at this

Hope it helps

Hi StefanK,

That link appears to not be working, will you please send it again? Thank you!

This is a https URL, search google for bombich loginwindowmanager logouthook

Great. Got it. Thanks again. :slight_smile:

Uh, that sure is a neat little script, made a few changes to make it a bit more dynamic



--cleanDesktop(false, true) -- Use remove method
--cleanDesktop(true, false) -- Use duplicate method

cleanDesktop(false, true)

on cleanDesktop(useDuplicate, useRemove)
	tell application "Finder"
		set today to do shell script "date +%d%M%Y"
		set mydocuments to path to documents folder as alias
		set mydesktop to path to desktop folder as alias
		set thedesktop to "Desktop"
		set thename to thedesktop & today
		if not (exists folder (thename) in mydocuments) then
			set thehome to (make new folder at mydocuments with properties {name:thename}) as alias
		else
			set thehome to ((mydocuments as text) & thename) as alias
		end if
		set everyfile to every file in mydesktop
		set everyfolder to every folder in mydesktop
		if useDuplicate then
			set useRemove to false
			duplicate everyfile to folder thehome
			duplicate everyfolder to folder thehome
		end if
		if useRemove then
			set useDuplicate to false
			move everyfile to folder thehome
			move everyfolder to folder thehome
		end if
	end tell
end cleanDesktop