* Plugin to Set the Title to be the same as the File Name?
Plugin to Set the Title to be the same as the File Name?
Hi Folks:
In a previous database I used the "Rename Selected Media Files (No ID)" to set the file name of media to be the same as the Title of the Media Record.
Background:
With this database I have a different issue: I had an issue at some point in the past with FTM 2019 with the media being attached to the wrong person (This is before I started naming media files and I was letting the ones from Ancestry get auto-named lik: 1900 Federal Census(9) . At some point the wrong media got attached to the wrong people.
Before importing this database/gedcom into FH 7, I had redownloaded and set the file name for about 1000 or so media files. FH7 though kept the 'original' titles that were auto created by FTM. So the file name is good, but the title is 'worthless'.
Question:
Is there a plugin or way to do the exact opposite of the "Rename Selected Media Files (No ID)" so that the file name becomes the Title? That is set the Title of each media to be the same as the file name.
After this, then I could go through and just change those needing it and then run the "Rename Selected Media Files (No ID) plugin.
Here is an example of some of the current records:
Matthew
In a previous database I used the "Rename Selected Media Files (No ID)" to set the file name of media to be the same as the Title of the Media Record.
Background:
With this database I have a different issue: I had an issue at some point in the past with FTM 2019 with the media being attached to the wrong person (This is before I started naming media files and I was letting the ones from Ancestry get auto-named lik: 1900 Federal Census(9) . At some point the wrong media got attached to the wrong people.
Before importing this database/gedcom into FH 7, I had redownloaded and set the file name for about 1000 or so media files. FH7 though kept the 'original' titles that were auto created by FTM. So the file name is good, but the title is 'worthless'.
Question:
Is there a plugin or way to do the exact opposite of the "Rename Selected Media Files (No ID)" so that the file name becomes the Title? That is set the Title of each media to be the same as the file name.
After this, then I could go through and just change those needing it and then run the "Rename Selected Media Files (No ID) plugin.
Here is an example of some of the current records:
Matthew
- Mark1834
- Megastar
- Posts: 2458
- Joined: 27 Oct 2017 19:33
- Family Historian: V7
- Location: South Cheshire, UK
Re: Plugin to Set the Title to be the same as the File Name?
Yes, I’ve got a custom plugin that does exactly that - it copies the case-sensitive file name (without the full path or file extension) to the title of the media record.
My PC is packed away at the moment during home office refurbishment, but I’ll check it on the laptop and post here either later today or tomorrow.
My PC is packed away at the moment during home office refurbishment, but I’ll check it on the laptop and post here either later today or tomorrow.
Mark Draper
Re: Plugin to Set the Title to be the same as the File Name?
Thank you Mark, that would be so helpful
Matthew
Matthew
- Mark1834
- Megastar
- Posts: 2458
- Joined: 27 Oct 2017 19:33
- Family Historian: V7
- Location: South Cheshire, UK
Re: Plugin to Set the Title to be the same as the File Name?
I have simplified the plugin, as my original carries out a number of additional checks that are very specific to my projects.
The attached plugin copies the media filename (without the full path and extension) to the Media Record title. You can select either automatic or prompted change. It is FH7 only, as this simplified extract uses fhFileUtils to extract the file name from the full path.
The attached plugin copies the media filename (without the full path and extension) to the Media Record title. You can select either automatic or prompted change. It is FH7 only, as this simplified extract uses fhFileUtils to extract the file name from the full path.
Mark Draper
Re: Plugin to Set the Title to be the same as the File Name?
Thank you very much Mark for your help. This plugin worked perfect and saved a lot of time
Matthew
Matthew
Re: Plugin to Set the Title to be the same as the File Name?
Dang. I was just logging in to look around and see if something like this was possible, and here it is.
You guys are so amazing.
But of course I have to ask if a small enhancement is possible...add the subdirectory to the name.
Appreciate any help.
You guys are so amazing.
But of course I have to ask if a small enhancement is possible...add the subdirectory to the name.
- file: P:\Genealogy\exhibits\birth_records\fisher_john-nh-birth-record.jpg
- desired title: birth_records\fisher_john-nh-birth-record.jpg
Appreciate any help.
Leslie P
Houston, TX
from TMG to RootsMagic to FH7
publish to web via TNG
Houston, TX
from TMG to RootsMagic to FH7
publish to web via TNG
- Mark1834
- Megastar
- Posts: 2458
- Joined: 27 Oct 2017 19:33
- Family Historian: V7
- Location: South Cheshire, UK
Re: Plugin to Set the Title to be the same as the File Name?
Leslie,
Doing that in one step might be tricky, but you should be able to do it in two steps.
line 34 of the plugin gives you the filename without path or extension (SplitPath.basename). If you change SplitPath.basename to SplitPath.abs_path you get the fully resolved name and path as the title, even for files in the project folder. It would also be possible to include the path but not the extension if that is preferred. Just change SplitPath.basename to SplitPath.parent .. '\\' .. SplitPath.basename
So in your case, your example title would be P:\Genealogy\exhibits\birth_records\fisher_john-nh-birth-record.jpg or P:\Genealogy\exhibits\birth_records\fisher_john-nh-birth-record.
To get to your final title, you will need to remove the unwanted leading part of the name, so a global search for P:\Genealogy\exhibits\ to replace with an empty string. Can the Search and Replace plugin do that selectively for media titles? I don't have it loaded, but it has lots of options. I'm sure Mike will be along later to clarify...
Make sure that you experiment on a copy of your project!
Doing that in one step might be tricky, but you should be able to do it in two steps.
line 34 of the plugin gives you the filename without path or extension (SplitPath.basename). If you change SplitPath.basename to SplitPath.abs_path you get the fully resolved name and path as the title, even for files in the project folder. It would also be possible to include the path but not the extension if that is preferred. Just change SplitPath.basename to SplitPath.parent .. '\\' .. SplitPath.basename
So in your case, your example title would be P:\Genealogy\exhibits\birth_records\fisher_john-nh-birth-record.jpg or P:\Genealogy\exhibits\birth_records\fisher_john-nh-birth-record.
To get to your final title, you will need to remove the unwanted leading part of the name, so a global search for P:\Genealogy\exhibits\ to replace with an empty string. Can the Search and Replace plugin do that selectively for media titles? I don't have it loaded, but it has lots of options. I'm sure Mike will be along later to clarify...
Make sure that you experiment on a copy of your project!
Mark Draper
- tatewise
- Megastar
- Posts: 28341
- Joined: 25 May 2010 11:00
- Family Historian: V7
- Location: Torbay, Devon, UK
- Contact:
Re: Plugin to Set the Title to be the same as the File Name?
The most straightforward change is to replace line 34 File = SplitPath.basename with:
Parent = SplitPath.parent:match( "[^\\]+$" ) extract last folder name without \ from parent folders
File = Parent .. "\\" .. SplitPath.basename construct parent with \ and filename
Parent = SplitPath.parent:match( "[^\\]+$" ) extract last folder name without \ from parent folders
File = Parent .. "\\" .. SplitPath.basename construct parent with \ and filename
Mike Tate ~ researching the Tate and Scott family history ~ tatewise ancestry
- Mark1834
- Megastar
- Posts: 2458
- Joined: 27 Oct 2017 19:33
- Family Historian: V7
- Location: South Cheshire, UK
Re: Plugin to Set the Title to be the same as the File Name?
Mike loves patterns . That's a good addition, but it might need to be set out slightly differently to make it clearer.
Replace the existing line 34 with these two lines if you want one folder level without the file extension (e.g. birth_records\fisher_john-nh-birth-record)
If you want to keep the file extension in the name, replace line 34 with theses two lines
Replace the existing line 34 with these two lines if you want one folder level without the file extension (e.g. birth_records\fisher_john-nh-birth-record)
Code: Select all
local Parent = SplitPath.parent:match("[^\\]+$")
local File = Parent .. "\\" .. SplitPath.basename
Code: Select all
local Parent = SplitPath.parent:match("[^\\]+$")
local File = Parent .. "\\" .. SplitPath.filename
Mark Draper
Re: Plugin to Set the Title to be the same as the File Name?
Must be something wrong.
If I select to run prompted, the popup shows the exact right title YAY!
I cancel out because I have 1104 media files and am not going to step through each one. I run automatic, the window tells me plugin completed, 1104 titles updated. All seems good.
But exactly zero titles are actually updated. I just tried it with the original plugin, same deal, all looks right as it's running, but nothing is being put into the media title field.
My media records have NO title right now, nothing at all. If that matters.
If I select to run prompted, the popup shows the exact right title YAY!
I cancel out because I have 1104 media files and am not going to step through each one. I run automatic, the window tells me plugin completed, 1104 titles updated. All seems good.
But exactly zero titles are actually updated. I just tried it with the original plugin, same deal, all looks right as it's running, but nothing is being put into the media title field.
My media records have NO title right now, nothing at all. If that matters.
Leslie P
Houston, TX
from TMG to RootsMagic to FH7
publish to web via TNG
Houston, TX
from TMG to RootsMagic to FH7
publish to web via TNG
- Mark1834
- Megastar
- Posts: 2458
- Joined: 27 Oct 2017 19:33
- Family Historian: V7
- Location: South Cheshire, UK
Re: Plugin to Set the Title to be the same as the File Name?
Sorry about that Leslie. The missing titles is the key difference. When a Media Record is created in FH, it is given the file name as a default title. Even if you clear this field in the Property Box, it still exists as an empty title. However, media imported from RM will not contain any title field, so there is nothing to change. FH doesn't distinguish between missing and empty titles for the prompt, but doesn't set values for missing ones unless it is created first.
This update fixes that issue, creating new title fields where none exist initially.
Your line to change for your customisation is now line 38 as I have added a version history to the top of the file. For interest, the additional line to create an empty title is line 54.
This update fixes that issue, creating new title fields where none exist initially.
Your line to change for your customisation is now line 38 as I have added a version history to the top of the file. For interest, the additional line to create an empty title is line 54.
- Attachments
-
- Name Media Record From File (0.1.1).fh_lua
- (1.97 KiB) Downloaded 51 times
Mark Draper
Re: Plugin to Set the Title to be the same as the File Name?
Worked perfectly! (on a copy of my database, I've not done it on the main yet, but will do soon)
Can't thank you enough for this. Now I can actually use the "title" field in the filter are on the media records page!
Can't thank you enough for this. Now I can actually use the "title" field in the filter are on the media records page!
Leslie P
Houston, TX
from TMG to RootsMagic to FH7
publish to web via TNG
Houston, TX
from TMG to RootsMagic to FH7
publish to web via TNG