Tack för ett bra script som öppnade mina AppleScript-ögon.
Funderade ett tag på hur jag vill att scriptet ska fungera i min dator och gjorde därför nedanstående variant. Testa gärna och återkom om ni gillar det.
Har försökt göra scriptet på så vis att det bara skapar de mappar som det verkligen finns filtyper till. Det är också ganska lätt att påverka vilka mappar man vill ha och vad dom ska innehålla.
Men som sagt prova gärna själv.
/Mats-Olof Liljegren
---------------------------------------------------------------------
-- Script to clean up the desktop folder
-- Made by e-pro, www.e-pro.se Mats-Olof Liljegren 2006
-- Use on your own risk!
-- You are free to use it and to change it after your need.
-- Pleace send me a copy if you make progress to the script.
---------------------------------------------------------------------
-- cleanupFolder = name of folder to put stuff in
set cleanupFolder to "Rensat skrivbord" as string
-- otherStuffFolder = name of folder to put not sortet files and folders in
set otherStuffFolder to "Övrigt" as string
-- Make lists of every filetype you want to sort in new folders in the cleanupFolder
-- First name is the new folder name for each file type
-- Make as many as you like
set fileType1 to {"Program", "APP"}
set fileType2 to {"Bilder", "BMP", "EPS", "GIF", "JPG", "PCT", "PICT", "PSD", "TIF", "TIFF", "PNG", "WBMP"}
set fileType3 to {"Databaser", "FP3", "FP5", "FP7"}
set fileType4 to {"Filmer", "MOV", "MPG", "MPEG", "WMV", "RM"}
set fileType5 to {"Ljud", "MP3", "waw"}
set fileType6 to {"Paket", "DMG", "GZIP", "PKG", "SEA", "SIT", "SMI", "TGZ", "ZIP", "RAR", "MPKG", "TAR"}
set fileType7 to {"PDF", "PDF"}
set fileType8 to {"Text", "DOC", "TXT", "clpt", "textClipping", "RTF"}
set fileType9 to {"Länkar", "LINK", "URL"}
set fileType10 to {"Flash", "FLA", "SWF"}
set fileType11 to {"CD-DVD-Master", "CDR", "cdr"}
set fileType12 to {"Excell", "xls"}
set fileType13 to {"AppleScript", "scpt"}
-- IMPORTANT
-- Put all file types in an array
set allTypes to {fileType1} & {fileType2} & {fileType3} & {fileType4} & {fileType5} & {fileType6} & {fileType7} & {fileType8} & {fileType9} & {fileType10} & {fileType11} & {fileType12} & {fileType13}
-- Error message if somethings goes wrong
set errorMessage to "Något gick fel, försök igen om du törs!"
try
tell application "Finder"
activate
-- Go through all types and get files for each type on desktop
set i to 1
repeat count allTypes times
set nameOnfolder to (item 1 of item i of allTypes) as string
set (item 1 of item i of allTypes) to every file of desktop whose name extension is in (item i of allTypes)
if (item 1 of item i of allTypes) is not {} then
if exists folder cleanupFolder then
set cleanupFolderAlias to item cleanupFolder as alias
else
make new folder with properties {name:cleanupFolder}
set cleanupFolderAlias to result
end if
set subFolder to ((cleanupFolderAlias as string) & (nameOnfolder as string))
if exists folder subFolder then
set subFolder to item subFolder as alias
else
make new folder at cleanupFolderAlias with properties {name:nameOnfolder}
set subFolder to result
end if
move (item 1 of item i of allTypes) to subFolder as alias
end if
set i to i + 1
end repeat
-- Get all folders on Desktop except the cleanupfolder and mounted disks
set otherStuffFolders to every folder of desktop whose name is not cleanupFolder and kind is not "enhet"
-- Get all files that are left on desktop
set otherStuffFiles to every file of desktop
if otherStuffFolders is not {} then
if exists folder cleanupFolder then
set cleanupFolderAlias to item cleanupFolder as alias
else
make new folder with properties {name:cleanupFolder}
set cleanupFolderAlias to result
end if
set subFolder to ((cleanupFolderAlias as string) & (otherStuffFolder as string))
if exists folder subFolder then
set subFolder to item subFolder as alias
else
make new folder at cleanupFolderAlias with properties {name:otherStuffFolder}
set subFolder to result
end if
move otherStuffFolders to subFolder as alias
end if
if otherStuffFiles is not {} then
if exists folder cleanupFolder then
set cleanupFolderAlias to item cleanupFolder as alias
else
make new folder with properties {name:cleanupFolder}
set cleanupFolderAlias to result
end if
set subFolder to ((cleanupFolderAlias as string) & (otherStuffFolder as string))
if exists folder subFolder then
set subFolder to item subFolder as alias
else
make new folder at cleanupFolderAlias with properties {name:otherStuffFolder}
set subFolder to result
end if
move otherStuffFiles to subFolder as alias
end if
end tell
on error
display dialog errorMessage
end try