pasteboard for OSX

Since the pasteboard plugin isn’t supporting OSX builds yet - I figured out another way to copy/paste strings to/from the pasteboard. You can find it here: 

https://code.coronalabs.com/code/pasteboard-copypaste-string-mac-osx-builds

@ojnab - this is awesome and came in handy big time for me this week. One suggestion, though: As written, your code doesn’t play nice with strings that include single-quotes. I made one small modification that (in my testing) makes it work as expected with strings that include single-quotes, double-quotes, or a combination of both.

Just change line 11 to this:

os.execute( [[echo "]]..string.gsub(s, '"', '\\"')..[[" | pbcopy]] )

And it should be good to go. I would also echo Perry’s comment that this module is ripe for a plugin implementation. :slight_smile:

Your quoting foo is strong but not invincible.  Your change will indeed work with single quotes but not protect $ signs (and some other shell punctuation such as backquotes).

Single quotes are the way to go and the way to escape single quotes in a single-quoted string is to replace them with ‘\’’  (for reasons which are beyond the scope of this post).

So the code should be:

os.execute( [[echo ']]..string.gsub(s, "'", "'\\''")..[[' | pbcopy]] )

Test case and result:

s = "\"Bob\" says that will be $5.50 for the 'unique' item" -- "Bob" says that will be $5.50 for the 'unique' item

@Perry - you are 2 for 2 today, sir! Amazing replies to both my forum posts today (https://forums.coronalabs.com/topic/59624-support-for-drag-file-onto-desktop-app-icon/) - you just might have a box 'o cookies in your future my good man. :grinning:

 Thanks! @ Schroderapps and Perry

I forgot to take quotes into consideration because it wasn’t necessary for my project.

I will update the gist code as you suggested and consider doing a plugin when I find the time.

And yes the drag file feature is very nice. Thumbs up Perry.

@ojnab - this is awesome and came in handy big time for me this week. One suggestion, though: As written, your code doesn’t play nice with strings that include single-quotes. I made one small modification that (in my testing) makes it work as expected with strings that include single-quotes, double-quotes, or a combination of both.

Just change line 11 to this:

os.execute( [[echo "]]..string.gsub(s, '"', '\\"')..[[" | pbcopy]] )

And it should be good to go. I would also echo Perry’s comment that this module is ripe for a plugin implementation. :slight_smile:

1 Like

Your quoting foo is strong but not invincible.  Your change will indeed work with single quotes but not protect $ signs (and some other shell punctuation such as backquotes).

Single quotes are the way to go and the way to escape single quotes in a single-quoted string is to replace them with ‘\’’  (for reasons which are beyond the scope of this post).

So the code should be:

os.execute( [[echo ']]..string.gsub(s, "'", "'\\''")..[[' | pbcopy]] )

Test case and result:

s = "\"Bob\" says that will be $5.50 for the 'unique' item" -- "Bob" says that will be $5.50 for the 'unique' item
1 Like

@Perry - you are 2 for 2 today, sir! Amazing replies to both my forum posts today (https://forums.coronalabs.com/topic/59624-support-for-drag-file-onto-desktop-app-icon/) - you just might have a box 'o cookies in your future my good man. :grinning:

 Thanks! @ Schroderapps and Perry

I forgot to take quotes into consideration because it wasn’t necessary for my project.

I will update the gist code as you suggested and consider doing a plugin when I find the time.

And yes the drag file feature is very nice. Thumbs up Perry.