Create MD file through Rename->Add Suffix script broken

As per the advice in this earlier thread ([url]"New with Clipboard' doesn't create Markdown text?]), I have been converting text documents (created via “new from clipboard” command after cutting text from longer markdown documents) to markdown documents with the script in the Rename folder “Add Suffix…”

However, that script now appears to only rename the “title” of the document rather than the filename itself. In other words, the script used to change the file suffix, but now it doesn’t. Has there been a recent change that would cause this issue?

It’s working here as expected. I ran the script with the Info pane open and “.md” was added to the title and the filename.

Ok, I’ve tried again and have discovered that the script works as expected on files with normal length file names. However, I create files with very long file names via this method:

  1. Paste in long text document of snippets of text from a PDF
  2. Cut (cmd-x) a snippet of text.
  3. New with clipboard (cmd-n)

These files are not responding to the script–I think likely because their files names are so long. Any suggestions on this issue?

Yes, use shorter names. Seriously.

Right. But I’m not choosing to use long file names. These are generated by the “new with clipboard” command.

You should select the file and rename it manually.

Right clicking on Named Markdown.templatescriptd and choosing Show Package Contents leads, through Resources > Contents > Scripts, to main.scpt

Glancing at the contents of that, I see that the first half constructs the (potentially long) suggested file name.

Can’t do it right now, but I would probably try inserting a truncation to some suitable maximum length. For example using this ‘take’ function, which also uses a ‘min’ function:

on run
    set strBrief to take(12, "antedeluvianmethodology")
end run

-- take :: Int -> [a] -> [a]
on take(n, xs)
    set blnString to (class of xs is string)
    if n > 0 then
        set m to min(n, length of xs)
        if blnString then
            text 1 thru m of xs
            items 1 thru m of xs
        end if
        if blnString then
        end if
    end if
end take

-- min :: Ord a => a -> a -> a
on min(x, y)
    if y < x then
    end if
end min

The Named Markdown template (user posted) works great! I actually have switched to that now–it doesn’t create the long file names. It’s the built in menu command “create new with clipboard” that does. I suppose I was trying to imply above that it’s poor form to blame users for errors related to long file names when the app itself is creating them. But no bother.

Forgive me – I was reading too fast

I’m glad you have a solution. Long live the flexibility of scripting interfaces :slight_smile: