Replace invalid characters in OpenInMarked.scpt

n8henrie's Avatar

n8henrie

30 Mar, 2013 07:36 PM

Just a quick workaround for invalid chars in note titles:

OpenInMarked.scpt chokes on nvALT filenames with invalid characters (since the actual filenames get replacement chars, but the note title retains the original chars, and the script uses UI scripting to grab the note title to try to find the actual file).

In my case, my note title had a ":" which was replaced with a "-" in the actual filename. Adding the following to OpenInMarked.scpt helped it find the file correctly.

on replace_chars(this_text, search_string, replacement_string)
    set AppleScript's text item delimiters to the search_string
    set the item_list to every text item of this_text
    set AppleScript's text item delimiters to the replacement_string
    set this_text to the item_list as string
    set AppleScript's text item delimiters to ""
    return this_text
end replace_chars

Then, immediately after setting p to the UI-script-derived note title,

 try
        set p to my replace_chars(p, ":", "-")
    end try

I imagine this same process could easily take a list of other invalid chars besides ":" to help make sure the file opens.

  1. Support Staff 1 Posted by Brett on 09 Apr, 2013 03:26 AM

    Brett's Avatar

    Nice. Another one was submitted that shells out to tr, but I like the pure AS solution. I'll test and incorporate it soon.

    -Brett

Reply to this discussion

Internal reply

Formatting help / Preview (switch to plain text) No formatting (switch to Markdown)

Attaching KB article:

»

Attached Files

You can attach files up to 10MB

If you don't have an account yet, we need to confirm you're human and not a machine trying to post spam.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac