Jump to content

Search the Community

Showing results for tags 'newline'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


  • Alfred 3
  • Make the Most of Alfred
    • Discussion & Help
    • Bug Reports
    • Alfred Feature Suggestions
    • Themes
  • Alfred Workflows
    • Share your Workflows
    • Workflow Help & Questions
  • Alfred v2 Themes
  • Alfred Remote for iOS
    • Alfred Remote Discussion & Help
    • Remote Connection Troubleshooting


  • Articles
    • Forum Integration
    • Frontpage
  • Pages
  • Miscellaneous
    • Databases
    • Templates
    • Media

Find results in...

Find results that contain...

Date Created

  • Start


Last Updated

  • Start


Filter by number of...


  • Start




Website URL




Found 2 results

  1. As of Alfred 2.0.3, it seems that passing multi-line text out from a script filter via the arg attribute (e.g., to the copy-to-clipboard action) is not supported: each newline is replaced with a space. I suspect this is a side effect of XML parsing, since the desired output value is stored in an XML attribute, and even though newlines are legal in attribute values, on passing the value out, XML parsers are expected to normalize the value by replacing all non-space whitespace characters with a space each, including \n (and \r\n) - see http://www.w3.org/TR/1998/REC-xml-19980210#AVNormalize Would be nice not to have this restriction, though, assuming my guess is correct, I'm not sure it's feasible with the current, XML-document-based approach. A workaround is below, but it is somewhat cumbersome. Workaround [updated on 2 May 2013 to incorporate David Ferguson's suggestion]: Inside the script filter, create a custom encoding where you replace newline chars. with a placeholder, e.g.: ⏎ Use the custom-encoded text as the value of the arg attribute. Add an intermediate script action that decodes the custom encoding by substituting newlines for the placeholders to restore the original value and then passes the restored value out.Sadly, since output from script actions cannot follow conditional paths based on keyboard modifiers, you'll have to duplicate the intermediate script action for every modifier combination you want to support, and attach the modifier-specific paths directly to the script filter. Download a demonstration workflow here: https://dl.dropboxusercontent.com/u/10047483/MultilineTextScriptFilterLimitationDemo.alfredworkflow Keyword "mt1" demonstrates the original limitation by attempting to copy a 2-line string passed from a script filter to the clipboard. Keyword "mt2" demonstrates the workaround. Workaround source code: Sample script-filter action (using /bin/bash: escape only backquotes, double quotes, backslashes, dollars): # Create sample multiline text. text=$'line 1\nline 2' # Derive a single-line representation for Alfred's result list. textForDisplay="${text//$'\n'/ ⏎ }" # Since linefeeds are inadvertently replaced by spaces when the value assigned to the `arg` attribute # is retrieved later, we assign a custom-encoded form of the output text in which we replace newlines # with placeholders. # In a subsequent, auxiliary script-action step we then perform unencoding to restore the original text. textEncoded=${text//$'\n'/⏎} cat <<EOF <?xml version="1.0"?> <items> <item arg="$textEncoded"> <title>$textForDisplay</title> <subtitle>Action to copy to clipboard and display notif.</subtitle> </item> </items> EOF Generic, directly reusable script action that unencodes (decodes) the custom encoding and relays the restored value (using /bin/bash; escape only backquotes, double quotes, backslashes, dollars): # Input is assumed to be custom-encoded text in which newlines have # been replaced with ⏎ chars. # We UNencode (decode) here in order to restore the newlines, and pass the # restored text out. v="{query}" echo -nE "${v//⏎/$'\n'}"
  2. The `arg` part of a script filter's result (the bit passed on as {query}) is oddly an XML attribute instead of an element. This makes it harder to pass on newlines in results--they just turn into spaces. The trick is to escape the newlines as an entity reference like: Most XML escape functions won't do that automatically, so you probably need to it yourself. Possibly double-quotes too. The best thing I came up with in Python is: from xml.sax.saxutils import escape safe_arg = escape(any_crazy_text, {'"': '"', '\n': ' '} ) I'd be happy to hear that there's a simpler way. Just passing this on since it stumped me at first.
  • Create New...