I want to create a folderaction or droplet that does the following:
set a spotlight-comment (text) to every file, folder and subfolder within a set folder
when adding new files and/or folders these shall be tagged as well with the spotlight-comment (text)
(3. the script shouldwork either as droplet (so that it moves the files/folders dropped on it to the set folder) or as a folderaction)
I am new to the AS-topic and have only done sth on copy&paste and try&error base.
If someoen can recommend me some tutorials (links or even hadcopies) I would appreciate it very much;)
THX very much for your help on my first topic and already THX in advance for this one
goeste
BTW. I have found some very intersting scripts in this section but as I reallyd on’t know how to modify them correctly, I bring up this thread.
Ok, I think what I want is not really easy to do. So I changeg plans.
I now create a new folder and tags it how I want it to on my desktop with the actual date when my MB user logs in . Does the folder already exist pops up an error message, ist it posible to shut that off?.
here is my code
set fDest to "leopard:users:goeste:desktop:"
set fD to date_format((current date))
set fTest to fDest & fD & ":"
set cD to date_format_comment((current date))
folder_check(fDest, fTest, fD, cD)
on folder_check(fDest, fTest, fD, cD)
try
get fTest as alias
return true
on error
tell application "Finder" to make new folder at fDest with properties {name:fD, comment:"IUAS, " & cD}
end try
end folder_check
on date_format(old_date) -- modified slightly to receive a date as input
set {year:y, month:m, day:d} to old_date
tell (y * 10000 + m * 100 + d) as string to text 1 thru 4 & text 5 thru 6 & text 7 thru 8
end date_format
on date_format_comment(old_date)
set {day:d, month:m, year:y} to old_date
tell (d * 1000000 + m * 10000 + y) as string to text 1 thru 2 & "." & text 3 thru 4 & "." & text 5 thru 8
end date_format_comment
Now I want to add a folderaction that tags all the files that will be dropped into the folder (including folders and files and new created folders). I thing that should not be that hard… but if it is, I’ll leave a note
The last thing I have do write is a droplet, that compresses the folder and moves the compressed folder to another one. Can someone please help me out with this little droplet???
This is a very simple folder action that will tag added items with the given comment. If you also need to tag the contents of added folders, then you will need to adjust the script and use the «entire contents» command of the Finder. The script won’t delete existing tags, but rather append the new one.
on adding folder items to watchfolder after receiving addeditems
repeat with addeditem in addeditems
tell application "Finder"
set existcomment to comment of addeditem
if existcomment is "" then
set comment of addeditem to "They Might Be Giants are great"
else
set newcomment to existcomment & space & "They Might Be Giants are great"
set comment of addeditem to newcomment
end if
end tell
end repeat
end adding folder items to
I know it was possible at some time in the Mac OS history, but I don’t know about the current state in Leopard.
No, you need to change the script a bit more to enable tagging of items in subfolders:
on adding folder items to watchfolder after receiving addeditems
repeat with addeditem in addeditems
set iteminfo to info for addeditem
if folder of iteminfo then
tell application "Finder"
set folderitems to entire contents of addeditem
end tell
repeat with folderitem in folderitems
my tagitem(folderitem)
end repeat
end if
my tagitem(addeditem)
end repeat
end adding folder items to
on tagitem(itemalias)
tell application "Finder"
set existcomment to comment of itemalias
if existcomment is "" then
set comment of itemalias to "They Might Be Giants are great"
else
set newcomment to existcomment & space & "They Might Be Giants are great"
set comment of itemalias to newcomment
end if
end tell
end tagitem
1: creating folder with current date as name and setting a folder action:
set fDestination to "leopard:users:goeste:desktop:"
set fDate to date_format((current date))
set fTest to fDestination & fDate & ":"
set cDate to date_format_comment((current date))
set fAction to "leopard:users:goeste:library:scripts:folder action scripts:addcomment.scpt"
on folder_check(fDestination, fTest, fDate, cDate, fAction)
try
get fTest as alias
return true
on error
tell application "Finder" to make new folder at fDestination with properties {name:fDate, comment:"IUAS, " & cDate}
tell application "System Events" to attach action to fTest using fAction
end try
end folder_check
on date_format(old_date) -- modified slightly to receive a date as input
set {year:y, month:m, day:d} to old_date
tell (y * 10000 + m * 100 + d) as string to text 1 thru 4 & text 5 thru 6 & text 7 thru 8
end date_format
on date_format_comment(old_date)
set {day:d, month:m, year:y} to old_date
tell (d * 1000000 + m * 10000 + y) as string to text 1 thru 2 & "." & text 3 thru 4 & "." & text 5 thru 8
end date_format_comment
folder_check(fDestination, fTest, fDate, cDate, fAction)
2: the folderaction to set the comments to the folders and files:
on adding folder items to watchfolder after receiving addeditems
repeat with addeditem in addeditems
set iteminfo to info for addeditem
if folder of iteminfo then
tell application "Finder"
set folderitems to entire contents of addeditem
end tell
repeat with folderitem in folderitems
my tagitem(folderitem)
end repeat
end if
my tagitem(addeditem)
end repeat
end adding folder items to
on tagitem(itemalias)
set cD to date_format_comment((current date))
tell application "Finder" to set comment of itemalias to "IUAS, " & cD
end tagitem
on date_format_comment(old_date)
set {day:d, month:m, year:y} to old_date
tell (d * 1000000 + m * 10000 + y) as string to text 1 thru 2 & "." & text 3 thru 4 & "." & text 5 thru 8
end date_format_comment
Use them as you want;)
Credits go to Martin, Julio and some guy named goeste
Your date_format() handler doesn’t insert any separators between the date elements, so it doesn’t need the text extractions and concatenations:
on date_format(old_date) -- modified slightly to receive a date as input
set {year:y, month:m, day:d} to old_date
return (y * 10000 + m * 100 + d) as string
end date_format
Your date_format_comment() handler will error when the day is less than 10 (ie. a single figure). You can either do it like this:
on date_format_comment(old_date)
set {day:d, month:m, year:y} to old_date
tell (y * 10000 + m * 100 + d) as string to return text 7 thru 8 & "." & text 5 thru 6 & "." & text 1 thru 4
end date_format_comment
. or, very slightly less efficiently, like this:
on date_format_comment(old_date)
set {day:d, month:m, year:y} to old_date
tell (100000000 + d * 1000000 + m * 10000 + y) as string to return text 2 thru 3 & "." & text 4 thru 5 & "." & text 6 thru 9
end date_format_comment