Run one script for a multiple selection

Hi,

I use the date changing script from DT and make some changes for that. The disadvantage is that is only for one selected item. It is possible to run it for a multiple choice of items like a list or a group?

The goal is to run a script for a multiple choice of item by item!

Thanks for helping!
Th.

The script Scripts > More Scripts… > Change Date supports actually multiple selected items. Or are you using a different script?

Hi, thanks for your answer!

Maybe I described the task incompletely. So I try it again.

I have a script that works fine for one selected item. The script changed the date of the item based on the file name like this “YYYY-MM-DD_nameoffile.pdf” Now I wish to run it for more then one item e.g. a multiply choice or an entire folder. Maybe it is to easy for some of you, but I find no way to run the script recursively for a set of selected items.

Each document has their own date, not the same. So the standard script from DT helps me not for multiple selected items.

Is there any way to help me?
Thanks all.
Th.

The script has to be modified so that it is able to support multiple selected items. Could you please post its code?

Hi, thanks for response.

Here is your code with my modifications:

-- Set creation/modification date
-- Created by Christian Grunenberg on Sun Mar 12 2006.
-- angepasst durch Thomas Z. im Dezember 2011 und Dezember 2012
-- Copyright (c) 2006. All rights reserved.

try
	tell application "DEVONthink Pro"
		set this_selection to the selection
		if this_selection is {} then error "Bitte erst eine Datei auswählen!"
		
		set theDate to (date of item 1 of this_selection)
		set theName to (name of item 1 of this_selection)
		set theMonth to ((month in theDate) as integer) as string
		set theDay to the day in theDate as string
		set theYear to the year in theDate as string
		
		if (theName as string) contains "_" then -- nur wenn die Dateinamenstruktur gegeben ist JJJJ-MM-TT_Text.xxx
			-- jetzt versuchen Datum aus Dateinamen zu holen ...
			set AppleScript's text item delimiters to "_"
			set theAnfangAusDateinamen to text items of theName
			set BindeStrichDatum to the first item of theAnfangAusDateinamen
			set AppleScript's text item delimiters to {""}
			if (BindeStrichDatum as string) contains "-" then -- nur wenn auch ein Datum möglich ist
				-- und nun noch das Datum in die Bestandteile zerlegen!
				set AppleScript's text item delimiters to "-"
				set theDatumAusAnfang to text items of BindeStrichDatum
				set theYear to the first item of theDatumAusAnfang
				set theMonth to the second item of theDatumAusAnfang
				if length of theDatumAusAnfang is 3 then -- falls ein Tag angegeben ist JJJJ-MM-TT_Text.
					set theDay to the third item of theDatumAusAnfang
				else
					set theDay to "01"
				end if
				-- und jetzt wieder den Trennungserkenner zurücksetzen ...
				set AppleScript's text item delimiters to {""}
			end if
		end if
		
		if (theDate as string) contains "." then
			set defaultDate to theDay & "." & theMonth & "." & theYear as string
			display dialog ("Die Datei:" & return & return & theName & return & return & "wird auf folgendes Erstelldatum (TT.MM.JJJJ) gesetzt:") with title ("Erstelldatum neu setzen") default answer defaultDate buttons {"Abbrechen", "OK"} default button 2 cancel button 1
		else
			set defaultDate to theMonth & "/" & theDay & "/" & theYear as string
			display dialog "Gib das Erstelldatum so ein MM/TT/JJJJ:" default answer defaultDate buttons {"Abbruch", "OK"} default button 2
		end if
	end tell
	
	set theDate to date (the text returned of the result)
	
on error error_message number error_number
	if the error_number is not -128 then
		try
			display alert "DEVONthink Pro" message error_message as warning
		on error number error_number
			if error_number is -1708 then display dialog error_message buttons {"OK"} default button 1
		end try
	end if
end try

Thanks again, Th.

This revision should work:



on getDate(theDateStr)
	return date (theDateStr)
end getDate

try
	tell application "DEVONthink Pro"
		set this_selection to the selection
		if this_selection is {} then error "Bitte erst eine Datei auswählen!"
		
		repeat with this_item in this_selection
			set theDate to (date of this_item)
			set theName to (name of this_item)
			set theMonth to ((month in theDate) as integer) as string
			set theDay to the day in theDate as string
			set theYear to the year in theDate as string
			
			if (theName as string) contains "_" then -- nur wenn die Dateinamenstruktur gegeben ist JJJJ-MM-TT_Text.xxx
				-- jetzt versuchen Datum aus Dateinamen zu holen ...
				set AppleScript's text item delimiters to "_"
				set theAnfangAusDateinamen to text items of theName
				set BindeStrichDatum to the first item of theAnfangAusDateinamen
				set AppleScript's text item delimiters to {""}
				if (BindeStrichDatum as string) contains "-" then -- nur wenn auch ein Datum möglich ist
					-- und nun noch das Datum in die Bestandteile zerlegen!
					set AppleScript's text item delimiters to "-"
					set theDatumAusAnfang to text items of BindeStrichDatum
					set theYear to the first item of theDatumAusAnfang
					set theMonth to the second item of theDatumAusAnfang
					if length of theDatumAusAnfang is 3 then -- falls ein Tag angegeben ist JJJJ-MM-TT_Text.
						set theDay to the third item of theDatumAusAnfang
					else
						set theDay to "01"
					end if
					-- und jetzt wieder den Trennungserkenner zurücksetzen ...
					set AppleScript's text item delimiters to {""}
				end if
			end if
			
			if (theDate as string) contains "." then
				set defaultDate to theDay & "." & theMonth & "." & theYear as string
				display dialog ("Die Datei:" & return & return & theName & return & return & "wird auf folgendes Erstelldatum (TT.MM.JJJJ) gesetzt:") with title ("Erstelldatum neu setzen") default answer defaultDate buttons {"Abbrechen", "OK"} default button 2 cancel button 1
			else
				set defaultDate to theMonth & "/" & theDay & "/" & theYear as string
				display dialog "Gib das Erstelldatum so ein MM/TT/JJJJ:" default answer defaultDate buttons {"Abbruch", "OK"} default button 2
			end if
			
			set date of this_item to my getDate(text returned of the result)
		end repeat
	end tell
on error error_message number error_number
	if the error_number is not -128 then
		try
			display alert "DEVONthink Pro" message error_message as warning
		on error number error_number
			if error_number is -1708 then display dialog error_message buttons {"OK"} default button 1
		end try
	end if
end try

Hi,
it works! And I’m happy. It will save a lot of time and steps in my workflow. Thanks so much!
Maybe there are other people how can use it, if you want you can include this idea in your official script in the “more scripts” library.

Thanks again,
Th.