LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 10-21-2020, 11:54 PM   #1
ziphem
Member
 
Registered: Feb 2004
Location: US / EU
Distribution: Fedora 31
Posts: 225

Rep: Reputation: 29
Script to edit metadata on multiple files, intended as a Nemo action menu item (but can't find "Icon-Name")


I searched for a script that allowed me to select one or several files in Nemo (Cinnamon) and add or edit metadata on them, but I couldn't find anything on point. So, I decided to write a small shell script for this purpose, intended to be used in Nemo as an action.

I haven't been able to figure out where I can find a list of the Icon-Names, so figured I'd put that question here. But my main purpose of this posting was to share this script in case someone else finds it useful. Works in Fedora 31, Cinnamon.

Code:
output=$(zenity --forms --title="Metadata field edit" --text="Metadata to create or update" --separator="," --add-combo "Metafield" --combo-values "URL|Author|Comment|Contributors|Copyright|CreateDate|EMail|Keywords|ModifyDate|OriginalDate|Phone|References|Software|Title|Address|City|Country|GPS|PostalCode|State|Altitude|Bearing|DateTime|Distance|Heading|Latitude|Longitude|Satellites|Speed" --add-entry="Metadata")
accepted=$?
if ((accepted != 0)); then
    echo "Something's wrong"
    exit 1
fi
metafield=$(gawk -F, '{ print $1 }'<<<$output)
metadata=$(gawk -F, '{ print $2 }'<<<$output)
exiftool -P -overwrite_original -$metafield=$metadata $1
For reference:
- Exif tags I used are from https://metacpan.org/pod/distributio...l/TagNames.pod
- Actions go in ~/.local/share/nemo/actions/
 
Old 10-22-2020, 03:55 AM   #2
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 19,872
Blog Entries: 12

Rep: Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053
Thanks for sharing!
 
Old 10-29-2020, 03:31 AM   #3
ziphem
Member
 
Registered: Feb 2004
Location: US / EU
Distribution: Fedora 31
Posts: 225

Original Poster
Rep: Reputation: 29
Embarrassingly, I'm back for help on the same script I posted. I tested it on filenames and paths without whitespaces. But now when I try it on any such files with whitespaces, it doesn't work!

How do I insert quotations around those folders / filenames with whitespaces when the entire block of them are passed in the positional parameter?

So let's say above I escape and quote the entire parameter:
Code:
exiftool -P -overwrite_original -$metafield=$metadata \"$@\"
and $@ represents like 5 jpg files, 1 through 5, the result is "1.jpg 2.jpg 3.jpg 4.jpg 5.jpg", rather than "1.jpg" "2.jpg" "3.jpg "4.jpg "5.jpg"

This script works in bash, so I think the issue is a Nemo one. The Nemo action script looks, in relevant part, like:
Code:
Exec=/home/me/.local/share/nemo/scripts/exif_edit.sh %F
so you see %F is passing all selected files.

Is there some method of substitution I can perform in the script so that it ignores or substitutes the whitespaces for purposes of processing them?

All I can think of is performing some sed or awk to find all patterns in $@ that start with "/home" and end with ".[jpg|gif|png|doc]" etc., place each matching pattern into an array, and then iteratively process each of these using the above exiftool command. Would something like this be a viable solution?

Thanks!

Last edited by ziphem; 10-29-2020 at 10:50 PM.
 
Old 10-31-2020, 12:25 AM   #4
ziphem
Member
 
Registered: Feb 2004
Location: US / EU
Distribution: Fedora 31
Posts: 225

Original Poster
Rep: Reputation: 29
Cool Final (working) script

Well jeeze, this was a painful 10 hours, but I finally got it working.

There seems to be some problems with passing whitespaces in the nemo action scripts; I verified this script worked in bash, but not when used via nemo action menu. Whitespaces become a problem when you have spaces in either your folders, your files, or both. I struggled for quite some time but managed a straightforward and what I believe is the simplest workaround. For completeness and full reference, I provide both the nemo action config along with the script.

So this time around, here is the complete working code in almost all scenarios.

Caveat: It does not work when there is a single quote in the filename. I'm a little cross-eyed at the moment, so if someone wants to adjust to permit that, that'd be great, otherwise I'll probably come back to update this post to allow for that.

/home/<whatever yours is>/.local/share/nemo/actions/exif.nemo_action
Code:
[Nemo Action]
Active=true
Name=Exif edit
Comment=Set metadata
Exec=<../scripts/exif_edit.sh '%F'>
#Exec=/home/<whatever yours is>/.local/share/nemo/scripts/exif_edit.sh '%F'
#Icon-Name=jpg
#EscapeSpaces=true
#Quote=single
Quote=double
#Quote=backtick
Selection=notnone
Extensions=png;bmp;gif;jpg;jpeg;
Mimetypes=image/*;
/home/<whatever yours is>/.local/share/nemo/scripts/exif_edit.sh
Code:
output=$(zenity --forms --title="Metadata field edit" --text="Metadata to create or update" --separator="," --add-combo "Metafield" --combo-values "URL|Author|Comment|Contributors|Copyright|CreateDate|EMail|Keywords|ModifyDate|OriginalDate|Phone|References|Software|Title|Address|City|Country|GPS|PostalCode|State|DateTime|Distance|Heading|Latitude|Longitude|Speed" --add-entry="Metadata")

# Cancel button exit
[[ "$?" != "0" ]] && exit 1

metafield=$(gawk -F, '{ print $1 }'<<<$output)
metadata=$(gawk -F, '{ print $2 }'<<<$output)

# No matter what, this didn't work, until I launched gnome-terminal and passed the line to run in it.
/usr/bin/gnome-terminal -e "exiftool -P -overwrite_original -$metafield='$metadata' $@"   #Action line

#echo /usr/bin/gnome-terminal -e "exiftool -P -overwrite_original -$metafield='$metadata' $@" > /home/<whatever yours is>/testing.txt   #Testing line

Last edited by ziphem; 10-31-2020 at 12:51 AM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Dose the menu item system/reboot and Shutdown have a .desktop file I can edit? questionsBot Bodhi 3 07-07-2020 06:31 PM
x11vnc: clipboard and right click menu(context menu) "Paste" item not in sync Vilius Linux - Desktop 0 11-17-2017 11:46 PM
System under attack via FTP, trying to understand the intended action mikeyt_333 Linux - Security 2 05-05-2006 09:44 AM
mozilla xpm kmenu item desktop item cjae Linux - Newbie 3 04-06-2005 07:11 AM
Can't edit item in Main Menu RockyZ Fedora 6 06-11-2004 09:27 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 12:54 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration