Move command issue with System Events


(Alberto González Ramírez) #1

Hi everybody.
I just want to clean my desktop and move every item to a folder in Documents.
This is the script.

set rutaCarpetaInboxDeDocumentos to ((path to documents folder) as text) & "inbox:"
set fechaActual to (current date) as text
set nombreCarpeta to "Limpieza de escritorio del " & fechaActual
tell application "System Events"
	set laCarpeta to make new folder at (folder rutaCarpetaInboxDeDocumentos) with properties {name:nombreCarpeta}
	move (disk items) of desktop to laCarpeta
end tell

I get an error with the command “move”: Can´t get every disk item of desktop.
Any help?

Thanks in advance.


(Phil Stokes) #2

how about:

tell application "Finder"
	set laCarpeta to make new folder at (folder rutaCarpetaInboxDeDocumentos) with properties {name:nombreCarpeta}
	move every file of desktop to laCarpeta
end tell


(Alberto González Ramírez) #3

Thanks @sphil!
It works ok in Finder. I already test it.
What I can’t understand is the reason why it doesn’t work in System Events.
It seems so simple…


(Nigel Garvey) #4

Hi.

  1. It’s possible that your (current date) as text result contains colons, which aren’t allowed in file or folder names. But I don’t know how time strings are formatted on your system.

  2. ‘desktop’ in System Events refers to the desktop picture settings. The desktop folder’s called the — er — ‘desktop folder’.

  3. ‘disk items’ in System Events include invisible files like “.DS_Store” and “.localized”.


(Alberto González Ramírez) #5

Thanks @NigelGarvey .
I made two changes.

  1. desktop -> path to desktop
  2. new variable (itemsToMove) to store the references to move.

And now, it works.

set path_to_inbox_folder to ((path to documents folder) as text) & "inbox:"
set current_date to (current date) as text
set desktop_folder to (path to desktop)
set folder_name to "Limpieza de escritorio del " & current_date

tell application "System Events"
	set itemsToMove to disk items of desktop_folder
	set theFolder to make new folder at (folder path_to_inbox_folder) with properties {name:folder_name}
	move itemsToMove to theFolder
end tell

Thanks again.