How to let the pictures in the groups become the icons in batches?

I just created a new database and started organizing again. It seems that the bug has been fixed by itself! ! However, maybe I didn’t make it clear before. For files without thumbnails, I don’t want the script to ignore it, but I want it to generate a group without thumbnails, and no error is reported. I wonder if it can be modified?

-- Group, copy tags, modification date, creation date and thumbnail, remove tags

tell application id "DNtp"
	try
		set theRecords to selection of think window 1
		if theRecords = {} then error "Nothing selected."
		
		repeat with thisRecord in theRecords
			set thisName to my recordName(name of thisRecord, filename of thisRecord)
			set thisParent to parent 1 of thisRecord
			set thisGroup to create record with {name:thisName, type:group} in thisParent
			move record thisRecord to thisGroup
			set tags of thisGroup to tags of thisRecord
			set tags of thisRecord to {}
			set modification date of thisGroup to modification date of thisRecord
			set creation date of thisGroup to creation date of thisRecord
			try
				set thumbnail of thisGroup to thumbnail of thisRecord
			end try
		end repeat
		
	on error error_message number error_number
		if the error_number is not -128 then display alert "DEVONthink" message error_message as warning
	end try
end tell

on replaceString(theText, oldString, newString)
	local ASTID, theText, oldString, newString, lst
	set ASTID to AppleScript's text item delimiters
	try
		considering case
			set AppleScript's text item delimiters to oldString
			set lst to every text item of theText
			set AppleScript's text item delimiters to newString
			set theText to lst as string
		end considering
		set AppleScript's text item delimiters to ASTID
		return theText
	on error eMsg number eNum
		set AppleScript's text item delimiters to ASTID
		error "Can't replaceString: " & eMsg number eNum
	end try
end replaceString

on recordName(theName, theFilename)
	set theSuffix to my getSuffix(theFilename)
	if theName ends with theSuffix and theName ≠ theSuffix then set theName to characters 1 thru -((length of theSuffix) + 2) in theName as string
	return theName
end recordName

on getSuffix(thePath)
	set revPath to reverse of characters in thePath as string
	set theSuffix to reverse of characters 1 thru ((offset of "." in revPath) - 1) in revPath as string
end getSuffix

QAQ Thank you soooooo much! !

hi, pete

The script you wrote is really easy to use! With its help, I have organized all my files. Thanks a million!

But as my understanding of DT gets deeper, it seems that I still need to make some final adjustments! I’m very sorry to disturb you again :pleading_face:

For some reason I want my database to “exclude group from tags”. During testing, I found that the script can successfully convert the file into a group (tag) with the same name, tags, and other metadata, but the file will be moved to the global inbox, it will not be placed in the newly generated group (tag).

In order to explain why I set up this way, I would like to share my file management method with you :stuck_out_tongue_closed_eyes:

I divided my database into two types, one for task management, the other for data collection, and both types of databases are firstly classified according to time.

For example:

  • Action (database)

    • Action 2019 (group)
    • Action 2020 (group)
  • Data (database)

    • Data 2019 (group)
    • Data 2020 (group)

(Roam, which is very popular now, also uses time to index each page)
(The reason why the task management database is named “Action” is because I want it to be ranked in front of “Data” when arranged in the order of names.)

In the task management database, each task is a Group. I use Tags and customized metadata for simple GTD filtering, and let Label implement the Kanban function.

I hope that all files will enter this database first to serve my ongoing tasks and I did not set this database “exclude group from tag”.

When the task is over, I will sort the files and let them enter the data collection database.

First of all, let me clarify the conceptual difference between files and Data in my system.
Files are items that are different from Group.
Data are similar to a concept in our minds.

For example, a director, I would treat him as a Data, and his avatar picture, his movie’s poster, video, etc. are files.

The data in this database has grown rapidly, so I split the timeline into months.
Such as:

  • Data 2020
    • Data 2020 01
    • Data 2020 02

These monthly named Group stores the movies I watched, the actors I like, and other data…
For example:

  • Group XXX (Movie’s name) with Tag “Movie”
  • Group XXX (Actor’s name) with Tag “Actor”

I hope that I can set what type of data I want to collect as a Tag, and each specific data as a group. In this way, one movie one group, one actor one group. I can store my post-watching notes, and actor stills in both groups with the replicate function.

I enabled “exclude group from tag” function for this database, because I want to use tags to describe groups and use groups to describe files.

If not, files can only be opened from the groups top to bottom missing the conditions for smart group filtering (It’s hard to search them with same name).

So I had to check off “exclude group from tag” and adjust this key script.

(I have asked some stupid questions in the community before, such as whether the location of replicate can be used as a filter condition for smart group, etc. In fact, all I need is to enable the “exclude group from tag” function)

As a student with poor memory, I feel very frustrated every time I can’t remember the expression of a sentence I want to quote when I write. Therefore, I want DT to help me remembering the connection between different data as much as possible, so that I can find what I need from multiple angles. The experience during this time has convinced me that DT is good at doing it and it is so stable and flexible! I really like it!

So, I am looking forward to discussing the details of the script with you, and I hope my sharing can help someone~

Sincerely, Fu

What are you trying to do this time? Obviously it is not what the script was written for. You want me to change it again, but change it to do what? Did you use it inside DEVONthink‘s tags group?

Yes! Due to the “exclude groups from tags” function, the group is just group tag. OK, let me explain! I want to complete these operations through the script:

  1. Generate group tag for each of selected file at the current location
  2. Duplicate the name, tag, creation time, modification time and thumbnail of each file to each group tag
  3. Delete the tags of each file, but do not delete the files in the original location
  4. Replicate the files to the corresponding group tags

This time I want to improve what you have explained before, that if you run this script on a file that has been replicated to somewhere, the file will be moved to the parent group not the newly generated group. So I adjusted the steps 3 and 4,(Moving before, Replicating this time) I don’t know if it will work :stuck_out_tongue_winking_eye:

Happy to receive your reply it is so kind of you :smile:

Sorry to bother you again. I tried to change the script myself, but the result was really confusing…
I changed move record thisRecord to thisGroup to replicate record thisRecord to thisGroup(This is so stupid), and the selected item was not successfully replicated to the the target group :woman_shrugging:.

I really shouldn’t ask for too much, I just want this script to work properly like before when I check off “exclude group from tags”.

I really need your help :sob:

I have no idea what you want to do.

Take some screenshots, annotate them with all steps and post them. Later I’ll try again to understand what you’re trying.

Is what you have in mind something like this?

-- Replicate (with "Exclude Groups from Tagging" disabled), copy tags, "remove" tags, modification date, creation date and thumbnail

tell application id "DNtp"
	try
		set theRecords to selection of think window 1
		if theRecords = {} then error "Nothing selected."
		
		repeat with thisRecord in theRecords
			set thisName to my recordName(name of thisRecord, filename of thisRecord)
			set thisParent to parent 1 of thisRecord
			set thisGroup to create record with {name:thisName, type:group} in thisParent
			replicate record thisRecord to thisGroup
			set tags of thisGroup to tags of thisRecord
			set tags of thisRecord to {thisName}
			set modification date of thisGroup to modification date of thisRecord
			set creation date of thisGroup to creation date of thisRecord
			try
				set thumbnail of thisGroup to thumbnail of thisRecord
			end try
		end repeat
		
	on error error_message number error_number
		if the error_number is not -128 then display alert "DEVONthink" message error_message as warning
	end try
end tell

on replaceString(theText, oldString, newString)
	local ASTID, theText, oldString, newString, lst
	set ASTID to AppleScript's text item delimiters
	try
		considering case
			set AppleScript's text item delimiters to oldString
			set lst to every text item of theText
			set AppleScript's text item delimiters to newString
			set theText to lst as string
		end considering
		set AppleScript's text item delimiters to ASTID
		return theText
	on error eMsg number eNum
		set AppleScript's text item delimiters to ASTID
		error "Can't replaceString: " & eMsg number eNum
	end try
end replaceString

on recordName(theName, theFilename)
	set theSuffix to my getSuffix(theFilename)
	if theName ends with theSuffix and theName ≠ theSuffix then set theName to characters 1 thru -((length of theSuffix) + 2) in theName as string
	return theName
end recordName

on getSuffix(thePath)
	set revPath to reverse of characters in thePath as string
	set theSuffix to reverse of characters 1 thru ((offset of "." in revPath) - 1) in revPath as string
end getSuffix

-- Replicate (with "Exclude Groups from Tagging" disabled), copy tags, "remove" tags, modification date, creation date and thumbnail

tell application id "DNtp"
	try
		set theRecords to selection of think window 1
		if theRecords = {} then error "Nothing selected."
		
		repeat with thisRecord in theRecords
			set thisName to my recordName(name of thisRecord, filename of thisRecord)
			set thisParent to parent 1 of thisRecord
			set thisGroup to create record with {name:thisName, type:group} in thisParent
			set modification date of thisGroup to modification date of thisRecord
			set creation date of thisGroup to creation date of thisRecord
			try
				set thumbnail of thisGroup to thumbnail of thisRecord
			end try
			
			set oldTags to tags of thisRecord
			set tags of thisGroup to oldTags
			set newTags to {}
			repeat with thisTag in oldTags
				if not (exists record at "/Tags/" & thisTag in current database) then
					set end of newTags to thisTag
				end if
			end repeat
			set tags of thisRecord to newTags
			
			replicate record thisRecord to thisGroup
		end repeat
		
	on error error_message number error_number
		if the error_number is not -128 then display alert "DEVONthink" message error_message as warning
	end try
end tell

on replaceString(theText, oldString, newString)
	local ASTID, theText, oldString, newString, lst
	set ASTID to AppleScript's text item delimiters
	try
		considering case
			set AppleScript's text item delimiters to oldString
			set lst to every text item of theText
			set AppleScript's text item delimiters to newString
			set theText to lst as string
		end considering
		set AppleScript's text item delimiters to ASTID
		return theText
	on error eMsg number eNum
		set AppleScript's text item delimiters to ASTID
		error "Can't replaceString: " & eMsg number eNum
	end try
end replaceString

on recordName(theName, theFilename)
	set theSuffix to my getSuffix(theFilename)
	if theName ends with theSuffix and theName ≠ theSuffix then set theName to characters 1 thru -((length of theSuffix) + 2) in theName as string
	return theName
end recordName

on getSuffix(thePath)
	set revPath to reverse of characters in thePath as string
	set theSuffix to reverse of characters 1 thru ((offset of "." in revPath) - 1) in revPath as string
end getSuffix

hi!
I’m sorry to let this thread be topped up again, I’m very sorry to disturb you again and again! :sob: To be honest, I find myself a little bit annoying, I should think carefully before asking for help! I recently found that it seems more convenient if I don’t move the tags from the items to the group. :persevere: I manually modified the files I organized before, and tried to modify the script myself, but it seems not easy. :frowning_face:

Please let me explain the changes I want to make this time (I promise this is the last time) :

image
It is still in the database where the “exclude groups from tags” option is unchecked,

image

  1. Generate a group for each selected item with the same name, time, thumbnail (Don’t tag the group with the old tags of the item, and don’t delete the tage of the item).
  2. Replicate item to this newly generated group.

I hope this modification will not take up too much of your time. Thanks a million! :rose: :rose: :rose:

It’s just a bit complicated when you don’t know what you want. But I’m sure you’ll find what works for you and there’s no problem to ask, so no worries.

This script results in this so I think this is what you want.

1

If checkParents is set to true and a record already has a parent with the record’s name and this parent is not in trash (or a normal tag) then no new group is created.

-- With "Exclude Groups from Tagging" disabled: Create group with name, creation date, modification date, thumbnail of selected record and replicate record to group

-- If checkParents is set to true and a record already has a parent with the record's name and this parent is not in trash (or a normal tag) then no new group is created.

property checkParents : true

tell application id "DNtp"
	try
		set theRecords to selection of think window 1
		if theRecords = {} then error "Nothing selected."
		set theTrashLocation to ("/" & (name of trash group of database id 1) & "/") as string
		
		repeat with thisRecord in theRecords
			set thisName to my recordName(name of thisRecord, filename of thisRecord)
			
			set createNewGroup to true
			
			if checkParents = true then
				if (name of parents of thisRecord) contains thisName then
					repeat with thisParent in (parents of thisRecord whose name = thisName)
						set thisLocation to location of thisParent
						if thisLocation ≠ theTrashLocation and thisLocation does not start with "/Tags/" then
							set createNewGroup to false
							exit repeat
						end if
					end repeat
				end if
			end if
			
			if createNewGroup = true then
				set thisParent to (first parent of thisRecord whose location ≠ theTrashLocation and location does not start with "/Tags/")
				set thisGroup to create record with {name:thisName, type:group} in thisParent
				set creation date of thisGroup to creation date of thisRecord
				try
					set thumbnail of thisGroup to thumbnail of thisRecord
				end try
				replicate record thisRecord to thisGroup
				set modification date of thisGroup to modification date of thisRecord
			else
				display notification "There's already a parent with this name"
			end if
		end repeat
		
	on error error_message number error_number
		if the error_number is not -128 then display alert "DEVONthink" message error_message as warning
	end try
end tell

on replaceString(theText, oldString, newString)
	local ASTID, theText, oldString, newString, lst
	set ASTID to AppleScript's text item delimiters
	try
		considering case
			set AppleScript's text item delimiters to oldString
			set lst to every text item of theText
			set AppleScript's text item delimiters to newString
			set theText to lst as string
		end considering
		set AppleScript's text item delimiters to ASTID
		return theText
	on error eMsg number eNum
		set AppleScript's text item delimiters to ASTID
		error "Can't replaceString: " & eMsg number eNum
	end try
end replaceString

on recordName(theName, theFilename)
	set theSuffix to my getSuffix(theFilename)
	if theName ends with theSuffix and theName ≠ theSuffix then set theName to characters 1 thru -((length of theSuffix) + 2) in theName as string
	return theName
end recordName

on getSuffix(thePath)
	set revPath to reverse of characters in thePath as string
	set theSuffix to reverse of characters 1 thru ((offset of "." in revPath) - 1) in revPath as string
end getSuffix

You are so kind! !
Yes it’s true, because I am new to DT, and I don’t know much about what AppleScript can do, so I’m still exploring ~ Thanks to your patience~ I will try the script you wrote. Thank you!