Workarounds for batch-saving pictures from Chatty, 2 different ones

ATTENTION: The below commands have been updated after the original post.

Hopefully soon Chatty will get a more straightforward way to save MMS pictures, but in the meantime I went looking for some commands and/or scripts to get it done.

=== WORKAROUND 1 ===

First:

  • Designate a folder where you want to move the Chatty MMS files to; I made a folder called “MMS” inside my main “Pictures” folder.
  • Within the designated folder (which, for me, is “MMS”), create a subfolder; I’ve named mine “ChatPics.”

Next:

Option 1

Run these commands in succession, one at a time in the terminal:
cp -nr /home/purism/.local/share/chatty/mms/. /home/purism/Pictures/MMS/

cd /home/purism/Pictures/MMS

find . -type f ! -name "*.*" -exec cp -n {} {}.png \;

find . -name \*.png -exec cp -n {} ChatPics \;

Chatty stores each MMS picture in a separate folder at .local/share/chatty/mms, but doesn’t add a file extension to the individual picture file within each folder. We need the .png to be added, so they can be recognized as pictures.

The above commands:

  • collect and copy all those picture files from the subfolders
  • place the copies in the Picture/MMS subfolder
  • change the directory (in Terminal) to the Pictures/MMS subfolder
  • add a .png file extension to each one
  • place the newly labeled photos in the ChatPics subfolder

Important: Run those commands in the given sequence so that you’re in the Pictures/MMS subdirectory (in the terminal) when you add the extension to the files that don’t have one. Otherwise, you’ll accidentally add a .png file extension to files you didn’t intend.

Option 2

Same commands as above, but combined into one shell script.

I created a text file with the following script inside… Thanks, Internet!

#!/bin/bash

commands () {
    cp -nr /home/purism/.local/share/chatty/mms/. /home/purism/Pictures/MMS/
    cd /home/purism/Pictures/MMS
    find . -type f  ! -name "*.*" -exec cp -n {} {}.png \;
    find . -name \*.png -exec cp -n {} ChatPics \;
}

export -f commands

gnome-terminal -e "bash -c 'commands'"

Then I saved it as chatpics (with no file extension) in the home folder, and made it executable (check the file’s Properties and Permissions).

To run it, you can either:

  • double-click it and select Run in Terminal, or
  • go to terminal and run the command ./chatpics

or:

set a cron job so that it runs at a given interval, e.g. once per hour, once per day, etc.

Option 3

Make a desktop “app” so you can simply click an icon to run it on demand.

  1. Open the text editor, paste in the following lines, save as ChatPics.desktop at .local/share/applications, and make sure it’s executable (check the file’s Properties and Permissions):
[Desktop Entry]
Name=ChatPics
Exec=./chatpics && exit
StartupNotify=true
Terminal=false
Type=Application
Categories=Utilities;
Icon=/home/purism/.local/share/icons/ChatPics.png
  1. Find an icon you like, name it ChatPics.png and save it at .local/share/icons.

===
Result:

Whether you use Options 1, 2, or 3, all the pictures from your chats will be collected and saved in one folder, where they will be easy to select/copy/cut/paste/move all together or in select groups. Only new picture files will be added each time; you won’t end up with multiple copies of the same ones.

You could also batch-save to the external card instead. but I use a different method to retain the entire Pictures directory and also back it up to the external card.

3 Likes

I would put /home/purism/ in front of that path. Assumptions about the current working directory on entry to the procedure / sequence of commands can be hazardous.

It wasn’t obvious to me where that is getting implemented.

2 Likes

Thanks. I’ve added it.

Nor to me, but in my testing I never ended up with multiple copies of the same picture files.

1 Like

Presumably because it keeps on overwriting?

So, yes, there’s no problem with multiple copies but if you don’t clean up the source directory then you will be copying more and more files and copying them all every time.

I’m thinking (completely untested!), add -n to the first cp and change the mv in the first find command into cp -n

The former change assumes that Chatty never updates any existing files in its directory tree i.e. only ever adds new folders and/or new files (as new messages come in).

Or, forget the first cp and run the find command on the source directory but doing -exec specifying a second shell script, which script handles the whole job more carefully. This is more the approach that I tend to use e.g. something like

if [ ! "$outputfile" -nt "$inputfile" ]; then
    ...create outputfile from input file in whatever way is appropriate
fi

So in this case, inputfile would be the full input path find -exec {} substitutes for {} and you would use basename to strip the directory from inputfile and then add the desired directory and suffix to get outputfile.

And in this case the creating of the file would be a simple cp of inputfile to outputfile.

Again, completely untested.

3 Likes

I’m not so sure it does. I checked the metadata on the files and they’re still showing the same time stamp as the originals, if we can judge from that, even though I’ve run the script a bunch of times without deleting the copies in MMS/ChatPics.

I’ll look into the rest of your post tomorrow. Thanks a lot for the ideas and input.

1 Like

Check also the time when they were changed (properties have that too, it’s different than the original creation time, which usually is preserved).

2 Likes

That’s because cp -a specifically asks to preserve such info (and then mv won’t change the file content at all).

2 Likes

@JR-Fi , @irvinewade
Well, I thought I had reviewed the “Modified” time stamp, but I actually did misread it - the copies moved into Pictures/MMS were overwriting themselves.

After some trial and error, I arrived at the following, which avoids the overwriting:

cp -nr in the first command
cp -n in the first “find” command
cp -n in the second “find” command

I’ve fixed the OP. Thanks.

2 Likes

=== WORKAROUND 2 ===
contributed by @irvinewade

This script authored by @irvinewade is much more efficient than my workaround (above), as you don’t end up with superfluous copies of folders; it assumes prior creation of /MMS/ChatPics within the main Pictures folder, as in my workaround (above/OP):

#!/bin/bash

# go to the home dir, then go to the Chatty MMS source directory
cd
cd .local/share/chatty/mms

# if no argument then find all the Chatty MMS images
if [ -z "$1" ]; then
	find . -type f  ! -name "*.*" -exec $0 {} \;
else
# else update our correctly named, sensibly located copy if necessary
	inputfile="$1"
	outputfile=~/Pictures/MMS/ChatPics/`basename "$inputfile"`.png

	if [ ! "$outputfile" -nt "$inputfile" ]; then
		echo "$inputfile"
		echo "    " "$outputfile"

		cp "$inputfile" "$outputfile"
	fi
fi

Very nice!

2 Likes

By the way, outgoing MMS pictures from Chatty won’t usually be collected and copied, as those images will typically already have a file extension in their name, e.g..jpg. (But, if an image already has a .png extension, then Workaround 1 will capture it, but Workaround 2 won’t, without a modification.) They would normally already exist somewhere in the user’s file system, created by the camera, download, transfer, etc., then sent as an outgoing MMS, so there’s probably no need to make an additional copy anyway.

When the user sends one of those images, the original file extension is retained in .local/share/chatty/mms when the record is created, unlike with incoming MMS, which don’t yet have a file extension.

2 Likes

Chatty’s full chat history is located at /home/purism/.purple/chatty/db/chatty-history.db.

The Matrix history (if applicable) is at /home/purism/.purple/chatty/db/matrix.db.

1 Like

Is your post here (number 9) the final version?

~s

Post 9 is @irvinwade’s script, which he provided to me, and is a different script from my original post, but is also much cleaner than what I came up with. (And yes, it’s ready to use.)

First:

  • open the Pictures folder
  • create a new folder called MMS
  • then inside the MMS folder, create another new folder called ChatPics.
    (This is just to make it match the script’s instructions.)

One simple way to run the script is to:

  • copy the text from inside that window (post #9) and

  • paste it into an empty text file.

  • Save it as a short name of your choice, with no file extension ( i.e. “myMMSscript” and not “myMMSscript.txt”) inside your Home folder.

  • Tap the file once and

  • then select Properties > Permissions from the menu (inside the Files app). (Or use the keyboard: Ctrl i.)

  • Click the box to enable “Allow executing file as program.”

  • Then you can simply double-tap the file and select “Run in terminal” in the little box that pops up.

A few seconds later, you can go to your Pictures folder, then MMS folder, then ChatPics folder. The images will be there.

1 Like

Regarding both workarounds in this thread:

There are other types of incoming MMS attachments besides images, and those will also get the .png file extension applied automatically by the script, even if they’re not images.

But those should be easy to deal with from inside the ChatPics destination folder the first time they don’t open as expected. You can just open it with a different application, change the file extension, or delete if not wanted.

And I guess other attachments that are images but which aren’t PNG.

For that reason there is no such thing as the final version of the script. :wink:

I don’t know the details of MMS but I would have assumed that the media type would be communicated from sender to receiver and hence a correct file type could have been given to the file in the Chatty directory - which would of course completely break both of the scripts in this topic. Alternatively, it is possible that the correct media type can be gleaned by examining more of the information in the Chatty directory, so that the final file in ChatPics will open the correct default application.

That will “break” my script though - because the output file will then not exist and, the next time the script runs, the original file name will be re-created. So if you have to change the file extension then you should do so with a copy, not a rename. Or you could extend the script to handle this scenario.

Likewise, you can’t delete an unwanted file - because it will just get re-created. If the file is truly unwanted then you need to delete the original MMS message within Chatty, where that is acceptable, and then delete the unwanted file.

1 Like