Is it possible to store and use the name of a property in a variable?

Hi,
I am attempting to write a handler that is passed the name of a property to read into a variable as a parameter. I pass the name of the property as a string but this fails. I have simplified the problem to the following test code:

set xmpTag to "xmp Keywords" -- property label

tell application "NeoFinder"
	
	set images to selected items -- get a list of all selected items
	repeat with anImage in images
		set originalKeywordString to xmp Keywords of anImage -- works
		set originalKeywordString to xmpTag of anImage -- fails
	end repeat
end tell

display dialog originalKeywordString

Is there a way of coercing the value of the string xmpTag into a property name ?

The script example I posted yesterday didn’t work as I thought. The Log Pane in the following example explains what was happening:

So, other than an if statement that contains the actual properties, I don’t know of a way to do what Simon wants.

Here is your script fixed…

set xmpTag to "name" -- property label

tell application "TextEdit"
	--set fileName to name of document 1 -- works
	set fileName to (run script xmpTag & " of document 1 of application \"TextEdit\"") -- works
end tell

display alert fileName

Since I don’t have the Application “NeoFinder”, for the script in the original post try this…

set xmpTag to "xmp Keywords" -- property label

tell application "NeoFinder"
	--set images to selected items -- get a list of all selected items
	repeat with i from 1 to count (selected items)
		--set originalKeywordString to xmp Keywords of anImage -- works
		set originalKeywordString to (run script xmpTag & " of item " & i & " of (selected items of application \"NeoFinder\")") -- try
	end repeat
end tell

display dialog originalKeywordString

Let me know if it works?

Here’s a more complex version that loops thru the selection in “Finder”…

set xmpTag to "kind" -- property label

tell application "Finder"
	set mySelection to selection
	repeat with i from 1 to count mySelection
		set originalKeywordString to (run script "tell application \"Finder\"" & linefeed & "set mySel to selection" & linefeed & "return " & xmpTag & " of item " & i & " of mySel" & linefeed & "end tell" & linefeed) -- works
		tell me to display dialog originalKeywordString
	end repeat
end tell
1 Like

Thanks Robert. That works great.

Just as a general aside, the run script command often causes an error when run inside a tell application statement:

This does no discernible harm, but an alternative that might be considered is:

Or you could take out everything not needed to be in a tell block like so…

set xmpTag to "kind" -- property label

tell application "Finder" to set mySelection to selection
repeat with i from 1 to count mySelection
	set originalKeywordString to (run script "tell application \"Finder\"" & linefeed & "set mySel to selection" & linefeed & "return " & xmpTag & " of item " & i & " of mySel" & linefeed & "end tell" & linefeed) -- works
	display dialog originalKeywordString
end repeat

Unfortunately it throws an error:
Screenshot 2025-03-11 at 14.48.40

I’ve tried various permutations of the examples above with NeoFinder but have been unable to get anything to work.

Thanks for trying.

On what line did it error?

OK I downloaded NeoFinder to play with.

Try this…

set xmpTag to "xmp Keywords" -- property label

local originalKeywordStrings
set originalKeywordStrings to (run script "tell application \"NeoFinder\" to get " & xmpTag & " of selected items") -- try

repeat with i from 1 to count originalKeywordStrings
	set originalString to item i of originalKeywordStrings
	display dialog originalString
end repeat
1 Like

I’ve only ever been able to do this with EXIFtool.
If you’re comfortable working with command line tools, it’s probably the simplest way to write XMP tags in bulk.

#robertfern Your line of code works a treat, many many thanks for taking the time to down load NeoFinder and find a line that works. Your one line will greatly simplify a script I am working on.

I have used exiftool in my previous script which is designed to import images from a camera card into a library folder. This script uses exiftool to rename the images with their capture time, updates the copyright, creates xmp sdecar files and links jpeg copies to their source raw/dng files by writing the sources name into the jpeg. So I have used it and its a great tool.

My present script aims to tidy up keywords in images in my image collection. For example when I took a close look at my images I realised that many subject names were stored using two keywords e.g. “Fred” and “Blogs” and that these would be better merged and written to what NeoFinder calls xmp persons.

The issue with using exiftool directly is presenting it with a list of images to change. In my use case I have a collection of over 100,000 images saved in many directories so the challenge is filtering this list to just those with the keywords Fred,Blogs before making the changes. There is probably a way to do this using embedded Perl commands but I don’t know Perl.

NeoFinder Applescript gives access to its database of images and searching for images tagged “Fred”,“Blogs” is quick enough to be usable. It just seemed sensible to use the NeoFinder image object to do the deletion of keywords “Fred”,“Blogs” followed by the assigning of the new keyword “Fred Blogs”. Again I am sure it could be done on the command line in a command line script except I am not familiar with command line scripting.

Under the bonnet NeoFinder uses exiftool and does much of the heavy lifting exposing a relatively friendly interface to Applescript.

S