¿Yo programando?

ACTUALIZACIÓN: Como era de esperarse es bastante porquería este script, funciona pero tiene bugs.

No es gran cosa pero es la primera vez que escribo una línea de código desde que copié el Breakout de una Micromanía y eso fue hace como 15 años.

Es un AppleScript para ponerlo como Folder Action y así organizar la carpeta de downloads, lo que hace es enviar los archivos a una carpeta dependiendo de su extensión, si la carpeta no existe la crea y si el archivo está repetido le cambia el nombre.

Claro que no lo hice yo en realidad lo saqué de mac osx hints pero por lo menos lo pude entender y hacerle un par de modificaciones.

Les dejo el código por si a alguno le sirve.

property image_extension_list : {"tif", "tiff", "gif", "png", "pict", "pct", "jpg", "bmp", "psd"}
property movies_extension_list : {"avi", "mov", "mpg", "ram"}
property music_extension_list : {"mp3"}
property archive_extension_list : {"zip", "sit", "sitx", "dmg", "tar", "hqx", "toast", "bin", "gz", "img"}
property text_extension_list : {"doc", "txt", "rtf", "pdf", "js", "htm", "html"}
property torrent_extension_list : {"torrent"}

property image_foldername : "Imagenes"
property movies_foldername : "Video"
property music_foldername : "Musica"
property archive_foldername : "Archivos"
property text_foldername : "Documentos"
property torrent_foldername : "Torrents"

on adding folder items to this_folder after receiving added_items
	try
		repeat with this_item in added_items
			tell application "Finder"

				if (the name extension of the this_item is in the image_extension_list) then

					my makeamove(this_item, this_folder, image_foldername)

				end if

				if (the name extension of the this_item is in the movies_extension_list) then

					my makeamove(this_item, this_folder, movies_foldername)

				end if

				if (the name extension of the this_item is in the music_extension_list) then

					my makeamove(this_item, this_folder, music_foldername)

				end if

				if (the name extension of the this_item is in the archive_extension_list) then

					my makeamove(this_item, this_folder, archive_foldername)

				end if

				if (the name extension of the this_item is in the text_extension_list) then

					my makeamove(this_item, this_folder, text_foldername)

				end if

				if (the name extension of the this_item is in the torrent_extension_list) then

					my makeamove(this_item, this_folder, torrent_foldername)

				end if

			end tell
		end repeat
	on error error_message
		display dialog error_message buttons {"OK"} default button 1
	end try

end adding folder items to

on makeamove(this_item, root_folder, target_foldername)

	tell application "Finder"

		if not (exists folder target_foldername of root_folder) then

			make new folder at root_folder with properties {name:target_foldername}
		end if

		set the target_folder to folder target_foldername of root_folder

		my resolve_conflicts(this_item, root_folder, target_folder)

		move file this_item to the target_folder

		--

	end tell

end makeamove

on resolve_conflicts(this_item, root_folder, target_folder) --renames the item if dublicate exists in target folder

	tell application "Finder"

		set file_extension to the name extension of this_item
		set the file_name to the name of this_item

		if the file_extension is "" then
			set the trimmed_name to the file_name
		else
			set the trimmed_name to text 1 thru -((length of file_extension) + 2) of the file_name
		end if

		if (exists document file file_name of target_folder) then

			set the name_increment to 1

			repeat
				set the new_name to (the trimmed_name & "_" & (name_increment as string) & "." & file_extension) as string

				if not (exists document file new_name of the target_folder) then

					set the name of document file file_name of folder root_folder to the new_name
					exit repeat
				else

					set the name_increment to the name_increment + 1

				end if
			end repeat
		end if
	end tell

	return the file_name
end resolve_conflicts

Lo que sería bueno es que alguien que sepa más que yo de esto (no se necesita mucho, como verán ni siquiera se como postear código) pudiera hacer que lea dentro de un zip o rar, sumara el peso de los archivos contenidos de la misma extensión, viera cual es el de más peso y enviara el zip a la carpeta correspondiente a esa extensión.

Jul 01 |General

Deja tu comentario