Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
file_renaming [2025/01/22 09:56] – [Variables] tnajdekfile_renaming [2025/04/16 11:47] (current) – Fixed a small copy-paste error tnajdek
Line 34: Line 34:
 ^ Variable ^ Description ^ ^ Variable ^ Description ^
 | ''authors'' | Parent item's principal creators (depending on the item type these are authors or artists but not editors or other contributors). | | ''authors'' | Parent item's principal creators (depending on the item type these are authors or artists but not editors or other contributors). |
 +| ''authorsCount'' | The number of the parent item's principal creators. //(Zotero 7.1)// |
 | ''editors'' | Parent item's editors. | | ''editors'' | Parent item's editors. |
 +| ''editorsCount'' | The number of parent item's editors. //(Zotero 7.1)// |
 | ''creators'' | All parent item's creators. | | ''creators'' | All parent item's creators. |
 +| ''creatorsCount'' | The total number of all parent item's creators. //(Zotero 7.1)// |
 | ''firstCreator'' | Parent item's creator (1–2 authors or editors), same as the value of the "Creator" column. | | ''firstCreator'' | Parent item's creator (1–2 authors or editors), same as the value of the "Creator" column. |
-| ''itemType'' | Parent item type. |+| ''itemType'' | Parent item type. Complete list of recognized item types can be found [[https://api.zotero.org/itemTypes|here]]  |
 | ''attachmentTitle'' | The title of the attachment that is being renamed or created |' | ''attachmentTitle'' | The title of the attachment that is being renamed or created |'
 | ''year'' | Year, extracted from parent item's date field. | | ''year'' | Year, extracted from parent item's date field. |
Line 56: Line 59:
 | ''regexOpts'' | All | 'i' | Defines [[https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_expressions#advanced_searching_with_flags|flags]] to use when matching using regular expressions (see ''replaceFrom''). For example, ''%%{{ title replaceFrom="\s+" regexOpts="g" }}%%'' is substituted with the parent item's title with all white space removed (without ''regexOpts'', only the first white space would be removed). | | ''regexOpts'' | All | 'i' | Defines [[https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_expressions#advanced_searching_with_flags|flags]] to use when matching using regular expressions (see ''replaceFrom''). For example, ''%%{{ title replaceFrom="\s+" regexOpts="g" }}%%'' is substituted with the parent item's title with all white space removed (without ''regexOpts'', only the first white space would be removed). |
 | ''match'' | All |  | Use a regular expression to test for a matching string in the variable. This parameter is useful in conditions and it cannot be used with any other parameters, except for ''regexOpts''. For example, the following template will only return the parent item's URL if the URL's domain name is zotero.org: ''%%{{ if {{ url match="^https?://zotero.org.*?$" }} }}{{ url }}{{ endif }}%%''. | | ''match'' | All |  | Use a regular expression to test for a matching string in the variable. This parameter is useful in conditions and it cannot be used with any other parameters, except for ''regexOpts''. For example, the following template will only return the parent item's URL if the URL's domain name is zotero.org: ''%%{{ if {{ url match="^https?://zotero.org.*?$" }} }}{{ url }}{{ endif }}%%''. |
-| ''max'' | ''authors'', ''editors'', ''creators'' |  | Limits number of creators to use, e.g., ''%%{{ editors max="1" }}%%'' will be replaced with first editor of parent's item. It can be configured with ''regexOpts'' parameter. |+| ''max'' | ''authors'', ''editors'', ''creators'' |  | Limits number of creators to use, e.g., ''%%{{ editors max="1" }}%%'' will be replaced with first editor of parent's item. |
 | ''name'' | ''authors'', ''editors'', ''creators'' | ''family'' | Customizes how creator name appears in the filename, with the following accepted options: ''family-given'' will use full name of the creator, beginning with family (last) name of the creator, ''given-family'' also uses full name but inverts the order, and options ''given'' and ''family'' will only use part of the parent item's creator's name. | | ''name'' | ''authors'', ''editors'', ''creators'' | ''family'' | Customizes how creator name appears in the filename, with the following accepted options: ''family-given'' will use full name of the creator, beginning with family (last) name of the creator, ''given-family'' also uses full name but inverts the order, and options ''given'' and ''family'' will only use part of the parent item's creator's name. |
 | ''name-part-separator'' | ''authors'', ''editors'', ''creators'' | '' ''(single space character) | Defines what characters to use to separate given and family name, especially useful when combined with ''initialize''. | | ''name-part-separator'' | ''authors'', ''editors'', ''creators'' | '' ''(single space character) | Defines what characters to use to separate given and family name, especially useful when combined with ''initialize''. |
Line 68: Line 71:
 A year of publication, followed by a hyphen-separated list of authors, followed by a title truncated at 30 characters: A year of publication, followed by a hyphen-separated list of authors, followed by a title truncated at 30 characters:
  
-Template: ''%%{{ year suffix="-" }}{{ authors name="family-given" initialize="given" initialize="-" join="-" suffix="-" case="hyphen" }}{{ title truncate="30" case="hyphen" }}%%''+Template:  
 +<code>{{ year suffix="-" }} 
 +{{ authors name="family-given" initialize="given" initialize="-" join="-" suffix="-" case="hyphen" }} 
 +{{ title truncate="30" case="hyphen" }} 
 +</code>
  
 Filename: ''2023-lee-sukbae-kim-ji-hoon-kwon-young-wan-the-first-room-temperature-amb.pdf'' Filename: ''2023-lee-sukbae-kim-ji-hoon-kwon-young-wan-the-first-room-temperature-amb.pdf''
Line 74: Line 81:
 Anything not included inside a ''%%{{%%'' bracket is copied to the filename literally: Anything not included inside a ''%%{{%%'' bracket is copied to the filename literally:
  
-Template: ''%%{{ itemType localize="true" }} from {{ year }} by {{ authors max="1" name="given-family" initialize="given" }}%%''+Template:  
 +<code>{{ itemType localize="true" }} from {{ year }} by {{ authors max="1" name="given-family" initialize="given" }} 
 +</code>
  
 Filename: ''Preprint from 2023 by S. Lee.pdf'' Filename: ''Preprint from 2023 by S. Lee.pdf''
Line 89: Line 98:
 {{ title }} {{ title }}
 {{ endif }}</code> {{ endif }}</code>
 +
 +As of Zotero 7.1, it's possible to compare numeric values like ''authorsCount'' using relational operators such as ''<'', ''%%<=%%'', ''>'', and ''>=''. For example, the following template checks the number of authors: if there are two or more, it uses the first author's name followed by et al.; if there are one or two authors, it includes all their names in the filename.
 +
 +<code>
 +{{ if {{ authorsCount > 2 }} }}
 +{{ authors max="1" suffix=" et al" }}
 +{{ else }}
 +{{ authors join=" & " }}
 +{{ endif }}
 +</code>
  
 It's possible to use regular expressions to match values and change the behavior of the template. For example, the following template preserves common attachment names (such as "Full Text"), but for attachments with non-matching titles, it uses the standard Zotero filename template: It's possible to use regular expressions to match values and change the behavior of the template. For example, the following template preserves common attachment names (such as "Full Text"), but for attachments with non-matching titles, it uses the standard Zotero filename template:
file_renaming.1737557766.txt.gz · Last modified: 2025/01/22 09:56 by tnajdek