This question is not answered. Helpful answers available: 2. Correct answers available: 1.


Permlink Replies: 13 - Pages: 1 - Last Post: 2 May 25, 11:28 Last Post By: davidekholm Threads: [ Previous | Next ]
ming666

Posts: 90
Registered: 27-Aug-2019
Search and display results from within the app
Posted: 30 Apr 25, 16:09
 
  Click to reply to this thread Reply
Is there a way to search across an entire album and display the results in the app window?

What I am trying to do is:

Display all photos whose filename begins with the same 4 characters and then assign keywords to just those photos.
JeffTucker

Posts: 8,081
Registered: 31-Jan-2006
Re: Search and display results from within the app
Posted: 30 Apr 25, 16:12   in response to: ming666 in response to: ming666
 
  Click to reply to this thread Reply
(Thread moved - the skin doesn't control what the jAlbum Explore mode does.)
davidekholm

Posts: 3,841
Registered: 18-Oct-2002
Re: Search and display results from within the app
Posted: 30 Apr 25, 17:30   in response to: ming666 in response to: ming666
 
  Click to reply to this thread Reply
Here's a small script you can run in jAlbum's system console that achieves just that (Groovy mode):
rootFolder.descendants.forEach(ao) -> {
	if (ao.name.startsWith("_SC_")) {
		ao.keywords = "foo,bar"
	}
}


Just replace the name pattern SC with what you want and "foo,bar" with the keywords you want. Now those keywords will be applied to all matching objects of the project.
Laza

Posts: 1,462
Registered: 6-Sep-2005
Re: Search and display results from within the app
Posted: 1 May 25, 07:08   in response to: davidekholm in response to: davidekholm
 
  Click to reply to this thread Reply
Is this an incremental change, or does it overwrite the existing keywords?
ming666

Posts: 90
Registered: 27-Aug-2019
Re: Search and display results from within the app
Posted: 1 May 25, 09:07   in response to: Laza in response to: Laza
 
  Click to reply to this thread Reply
I can report that it overwrites
ming666

Posts: 90
Registered: 27-Aug-2019
Re: Search and display results from within the app
Posted: 1 May 25, 09:08   in response to: davidekholm in response to: davidekholm
 
  Click to reply to this thread Reply
davidekholm wrote:
Here's a small script you can run in jAlbum's system console that achieves just that (Groovy mode):
rootFolder.descendants.forEach(ao) -> {
	if (ao.name.startsWith("_SC_")) {
		ao.keywords = "foo,bar"
	}
}

Just replace the name pattern SC with what you want and "foo,bar" with the keywords you >want. Now those keywords will be applied to all matching objects of the project.


Thank you. It works well.
Is there a way to make it incremental instead of overwriting?
RobM

Posts: 3,899
Registered: 4-Aug-2006
Re: Search and display results from within the app
Posted: 1 May 25, 12:03   in response to: ming666 in response to: ming666
 
  Click to reply to this thread Reply
You could use
rootFolder.descendants.forEach(ao) -> {
  if (ao.name.startsWith("_SC_")) {
  keywords = ao.getKeywords()
  keywords += ",foo,bar"
  ao.setKeywords(keywords)
  println(ao)
  }
}
JeffTucker

Posts: 8,081
Registered: 31-Jan-2006
Re: Search and display results from within the app
Posted: 1 May 25, 12:53   in response to: RobM in response to: RobM
 
  Click to reply to this thread Reply
Just wondering if having a leading comma might cause problems. Would it be safer to check the existing keywords for emptiness, first? If it's empty, make it foo, bar. But if it's not empty, append ,foo,bar.
RobM

Posts: 3,899
Registered: 4-Aug-2006
Re: Search and display results from within the app
Posted: 1 May 25, 14:41   in response to: JeffTucker in response to: JeffTucker
 
  Click to reply to this thread Reply
JeffTucker wrote:
Just wondering if having a leading comma might cause problems. Would it be safer to check the existing keywords for emptiness, first? If it's empty, make it foo, bar. But if it's not empty, append ,foo,bar.
Not tried it but I think a leading comma would be ignored, like it was an empty string.
Just in case:
rootFolder.descendants.forEach(ao) -> {
  if(ao.name.startsWith("_SC_")) {
  keywords = ao.getKeywords()
  if(keywords == null | keywords.equals(""))
  ao.setKeywords("fo,bar")
  else
   keywords += ",foo,bar"
  ao.setKeywords(keywords)
  println(ao)
  }
}
davidekholm

Posts: 3,841
Registered: 18-Oct-2002
Re: Search and display results from within the app
Posted: 1 May 25, 15:24   in response to: RobM in response to: RobM
 
  Click to reply to this thread Reply
Here's a modified version that simply ADDS the listed keywords:
rootFolder.descendants.forEach(ao) -> {
  if (ao.name.startsWith("_SC_")) {
    var kw = ao.keywordSet
    kw.add("foo")
    kw.add("bar")
    ao.keywords = kw
  }
}
ming666

Posts: 90
Registered: 27-Aug-2019
Re: Search and display results from within the app
Posted: 1 May 25, 15:26   in response to: davidekholm in response to: davidekholm
 
  Click to reply to this thread Reply
Thank you
davidekholm

Posts: 3,841
Registered: 18-Oct-2002
Re: Search and display results from within the app
Posted: 1 May 25, 15:31   in response to: davidekholm in response to: davidekholm
 
  Click to reply to this thread Reply
It strikes me I once made a very flexible API that handles long running tasks with progress bars and the ability to undo everything as a group + it pops up a dialog when it's done = better feedback. Here's a modified version using that API:
Work.on(rootFolder.descendants)
	.titled("Add multiple keywords")
	.filter(ao -> ao.name.startsWith("_SC_"))
	.forEach(ao) -> {
		var kw = ao.keywordSet
		kw.add("foo")
		kw.add("bar")
		ao.keywords = kw
	}.showResult()
 


You can modify this code to only apply to selected objects by replacing rootFolder.descendants by selectedObjects. To have it apply to all objects of the current folder, replace rootFolder.descendants with currentFolder.children.

Edited by: davidekholm on 2 May 2025, 11:27: Modified to use filter instead of an if-clause, as that creates a correct reporting on # of objects processed.
ming666

Posts: 90
Registered: 27-Aug-2019
Re: Search and display results from within the app
Posted: 1 May 25, 15:39   in response to: davidekholm in response to: davidekholm
 
  Click to reply to this thread Reply
Thanks again
davidekholm

Posts: 3,841
Registered: 18-Oct-2002
Re: Search and display results from within the app
Posted: 2 May 25, 10:25   in response to: ming666 in response to: ming666
 
  Click to reply to this thread Reply
You're welcome
Legend
Forum admins
Helpful Answer
Correct Answer

Point your RSS reader here for a feed of the latest messages in all forums