You can make a difference in the Apple Support Community!

When you sign up with your Apple Account, you can provide valuable feedback to other community members by upvoting helpful replies and User Tips.

Hidden characters in exported image filename

This was previously reported but the issue was closed due to lack of activity.

It was Hidden characters in exported image filen… - Apple Community


I am running into this now.


When exporting Keynote slides as images some hidden characters are added to the filename. In this case a question mark (?) is added as the first character in the file name and also after the period. These characters are not visible in the Finder window, they are only visible when doing an "ls" from Terminal.


I use Keynote to draw images that are included into Markdown documents



![caption](./figures/KeynotePres/KeynotePres.001.png)


My figure inclusion no longer works because of the strange characters.


There *is* a workaround, but it is ugly. I need to insert the unprintable characters into the Markdown document at the positions marked with an X.


![caption](./figures/KeynotePres/XKeynotePres.X001.png)


Using Emacs, on Linux, this can be done with


CTL-x 8 [RET] 2 0 0 e [RET]


The result is a figure inclusion string that has the unprintable character, and you can't tell in the Emacs text file. Very unpleasant.

MacBook Pro 15″, macOS 12.7

Posted on Nov 15, 2024 9:56 AM

Reply
1 reply

Nov 15, 2024 10:08 AM in response to tomsheffler

Ok, here is a python script to remove the unprintable characters in the current directory.


#!/usr/bin/python3
#
# Fix up the filenames emitted by Keynote.  What a piece of ????!

import os
import re

def clean_filename(filename):
    """Removes unprintable characters from a filename."""
    # return re.sub(r'[^A-Za-z0-9\._-]', '_', filename)
    # TOM: instead of underscore, just delete
    return re.sub(r'[^A-Za-z0-9\._-]', '', filename)

def clean_filenames_in_dir(directory):
    """Cleans filenames in the specified directory."""
    for filename in os.listdir(directory):
        old_path = os.path.join(directory, filename)
        new_filename = clean_filename(filename)
        if filename != new_filename:
            new_path = os.path.join(directory, new_filename)
            os.rename(old_path, new_path)
            print(f"Renamed: {old_path} -> {new_path}")

if __name__ == "__main__":
    target_directory = "."
    clean_filenames_in_dir(target_directory)

Hidden characters in exported image filename

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.