Pass arguments to triggered scripts?

Is there any way to pass parameters to Applescripts triggered by DTP?

I have several RSS feeds in one of my big databases, and I use Applescripts to (1) download the targets of the feed items as web archives and (2) rename them using the scheme “Source–Title.” For example, a story “Man Bites Dog” from the New York Times feed would be renamed “New York Times–Man Bites Dog”. Currently I use a distinct script for each feed, with the name of the source hard-coded into each script. But (1) this is less than ideal, since the scripts all do exactly the same thing, and (2) it’s tedious to make changes to every single script when I decide to tweak the implementation. I could consolidate the scripts into one, if I could simply pass the name of the source as an argument.

It’s not possible to easily “pass parameters to Applescripts triggered by DTP” – however we might need a little more information about what you mean by that.

When you mention “triggered” do you mean a script that is attached to a group in Tools > Show Info > Script? That type of script uses a particular structure, for example:


on triggered(theRecord)
	try
		tell application id "com.devon-technologies.thinkpro2"
			[do some stuff]
		end tell
	end try
end triggered

In this case, “theRecord” is the group to which the script is attached. You could get data (say, the name of the group) from “theRecord” and use it to name the children of “theRecord” – that is, the documents inside that group.

Or, if you don’t want to do it that way, and you want to run the script from the Script menu or some other way, then use a dialog to prompt for the prefix. See, for example, the “Add Prefix” script that comes with DEVONthink:

tell application id "com.devon-technologies.thinkpro2"
	try
		set this_selection to the selection
		if this_selection is {} then error "Please select some contents."
		
		repeat
			set prefix to display name editor "Add Prefix" info "Prefix:"
			if prefix is not "" then exit repeat
		end repeat
		
		repeat with this_item in this_selection
			set current_name to the name of this_item
			set new_item_name to prefix & current_name
			set the name of this_item to new_item_name
		end repeat
	on error error_message number error_number
		if the error_number is not -128 then display alert "DEVONthink Pro" message error_message as warning
	end try
end tell

Or, don’t write a custom script but use one of the inbuilt renaming scripts, including those available as extras from Help > Support Assistant

First, thanks for the suggested workarounds. And yes, I did mean scripts triggered by clicking on groups (rather than user-activated from the scripts menu); sorry that wasn’t clear.

For an example of what I have in mind, consider a script my_script.scpt:


on run argv
    return "Hello " & (item 1 of argv) & "!"
end run

Run this from the command line (in Terminal):


~$  osascript my_script.scpt Dan
Hello Dan!
~$ osascript my_script.scpt Michelle
Hello Michelle!

Hopefully this makes it clear what I want to do in the functional script: pass the name of the source as the second argument (after the record itself). Then no need to hard-code the source name or check the name of the feed against a library of source names or any of that.

(Example from here: http://hints.macworld.com/article.php?story=20050523140439734)

As it happens, I was already able to comprehend the concept of passed arguments.

Triggered scripts attached to a group or document and activated by clicking on that group or document are passed the record and its properties (e.g., “on triggered(theRecord)”). Your script can examine those properties and perform logic using the property values. So, as mentioned in my last post, you could get the name property of the group from "theRecord"and use name to calculate names for the child records of the group. In that approach, the group’s name acts as a passed argument to the triggered script.