|
|
|
01-21-2017, 09:18 PM
|
#1
|
Human being with feelings
Join Date: Jul 2015
Location: Yekaterinburg, Russia
Posts: 400
|
afxLua (clipboard) library error
how to make this lua module work http://files.luaforge.net/releases/j...ipboard/1.0.0?
I need to get text from clipboard and set text to clipboard.
I didn't find anything other than that
os.execute('echo | set /p="'..str..'"| clip') works but annoying cmd window appears every time.
It seems clipboard works only with lua 5.1 and 5.2 (Reaper uses 5.3 and 5.33).
I followed these instructions: http://stackoverflow.com/questions/2...in-lua-windows
I put clipboard.dll in Program Files\REAPER (x64) and write require "clipboard". And I got such error: Program Files\REAPER (x64)\clipboard.dll': is not a valid Win32 application
What's wrong?)
|
|
|
01-22-2017, 02:22 AM
|
#2
|
Human being with feelings
Join Date: May 2015
Location: Québec, Canada
Posts: 4,937
|
REAPER's Lua cannot load pre-built Lua extensions. Here's what I use to read/write to the clipboard: cfillion_Clipboard Copy and Paste.lua.
It works well (on macOS) except on Windows where: - it's very slow
- a cmd.exe window pops up as you mentionned
- the z-order of window may change once the command prompt closes
- it does not work at all on 32-bit REAPER (it fails with a "no error" error message, see https://forum.cockos.com/showthread.php?t=179280)
GetClipboard/SetClipboard API functions would be useful. Want to post a FR?
Last edited by cfillion; 01-22-2017 at 05:04 AM.
|
|
|
01-22-2017, 02:58 AM
|
#3
|
Human being with feelings
Join Date: Jul 2015
Location: Yekaterinburg, Russia
Posts: 400
|
Quote:
Originally Posted by cfillion
|
In Python by the way it goes without any popups:
Code:
import pyperclip
pyperclip.copy('Hello world.')
But afaik Python does not understand gfx functions (gfx.init, gfx.drawstr etc)
So I can't use its pyperclip.copy in my GUI scripts. It's a pity )
Quote:
Originally Posted by cfillion
GetClipboard/SetClipboard API functions would be useful. Want to post a FR?
|
It would be useful functions, indeed. Can you post it pls? you sounds more convincing (and perhaps you have a couple of good reasons to have this APIs)
|
|
|
01-22-2017, 08:45 AM
|
#4
|
Human being with feelings
Join Date: Feb 2007
Location: Oulu, Finland
Posts: 8,062
|
The Reaper API now has ExecProcess which can launch an external process without showing the console window.
__________________
I am no longer part of the REAPER community. Please don't contact me with any REAPER-related issues.
|
|
|
01-22-2017, 10:19 PM
|
#5
|
Human being with feelings
Join Date: Jul 2015
Location: Yekaterinburg, Russia
Posts: 400
|
Quote:
Originally Posted by Xenakios
The Reaper API now has ExecProcess which can launch an external process without showing the console window.
|
Oh it's cool) I forgot about it.
UPD: just got that I don't understand ExecProcess function.
Xen could you explain pls what i'm doing wrong?
Code:
os.execute('echo | set /p="123456"| clip')
-- that works
Code:
reaper.ExecProcess('echo | set /p="123456"| clip', 10)
-- this doesn't work (doesn't set '123456' to my clipboard)
And guys could you tell me pls if there's a way to run a python script from lua one?
I'm trying to use this construction
Code:
reaper.Main_OnCommand(reaper.NamedCommandLookup(PYTHON_SCR_ID),0)
and it doesn't work
but this does work
Code:
reaper.Main_OnCommand(reaper.NamedCommandLookup(LUA_SCR_ID),0)
is this a bug or something?
|
|
|
01-23-2017, 03:46 AM
|
#6
|
Human being with feelings
Join Date: May 2015
Location: Québec, Canada
Posts: 4,937
|
ExecProcess doesn't run a shell, so one must be used to understand echo, set and the pipes. Also on Windows it doesn't work with a timeout for some reason (failing with status 259).
Code:
reaper.ExecProcess('cmd.exe /c echo | set /p="123456"| clip', 0)
reaper.ExecProcess('/bin/sh -c "echo hello world | pbcopy"', 0)
I don't know how to properly escape quotes and newlines from user input so they can be copied (beside, I'm uneasy with inserting arbitrary data into the command line).
I also tried pasting with
Code:
reaper.ExecProcess('powershell -Command Get-Clipboard', 0)
On Windows 10 it's better than io.popen but on Windows 7 it completely freezes up REAPER and I have no idea why. (With a timeout set it fails – 259 – on both Windows but is fine on macOS)
Quote:
Originally Posted by me2beats
And guys could you tell me pls if there's a way to run a python script from lua one?
|
This works here (macOS):
Code:
reaper.SetExtState('pyperclip', 'copy', 'text to "copy"', false)
id = reaper.NamedCommandLookup('_RSfcac7b3e442722c4425a8b37ac3ec1c13e1eb01b')
reaper.Main_OnCommand(id, 0)
Code:
import pyperclip
pyperclip.copy(RPR_GetExtState('pyperclip', 'copy'))
RPR_DeleteExtState('pyperclip', 'copy', False)
Last edited by cfillion; 01-23-2017 at 06:11 AM.
|
|
|
01-23-2017, 06:41 AM
|
#7
|
Human being with feelings
Join Date: Jul 2015
Location: Yekaterinburg, Russia
Posts: 400
|
Quote:
Originally Posted by cfillion
Code:
reaper.ExecProcess('cmd.exe /c echo | set /p="123456"| clip', 0)
|
Oh my! This really works, it's great!
Quote:
Originally Posted by cfillion
Code:
reaper.SetExtState('pyperclip', 'copy', 'text to "copy"', false)
id = reaper.NamedCommandLookup('_RSfcac7b3e442722c4425a8b37ac3ec1c13e1eb01b')
reaper.Main_OnCommand(id, 0)
Code:
import pyperclip
pyperclip.copy(RPR_GetExtState('pyperclip', 'copy'))
RPR_DeleteExtState('pyperclip', 'copy', False)
|
Oh my! This really works, it's great! (copied with pyperclip)
PS: it's strange that I tried this several hours ago with no success.
Quote:
Originally Posted by cfillion
I don't know how to properly escape quotes and newlines from user input so they can be copied (I'm uneasy with inserting arbitrary data into the command line).
|
I did it like that (before this day):
Code:
local r = reaper
local str = [=[
str1
str2
etc
]=]
local function write (file, str)
local file_open = io.open(file, 'w'); file_open:write(str); file_open:close()
end
local resources = r.GetResourcePath()
local clipboard_file = resources..'\\clipboard.txt'
write (clipboard_file, str)
os.execute('clip < '..clipboard_file)
but reaper.ExecProcess("cmd.exe /c 'clip < '..clipboard_file", 0) instead of os.execute('clip < '..clipboard_file) doesn't work, how to write it correctly?
|
|
|
01-23-2017, 07:43 AM
|
#8
|
Human being with feelings
Join Date: Jul 2015
Location: Yekaterinburg, Russia
Posts: 400
|
Ok I found my way for a while
I will use lua+python(+pyperclip)
python script:
Code:
import pyperclip
s = RPR_GetExtState('pyperclip', 'copy')
s = s.replace("\n", "\r\n")
pyperclip.copy(s)
RPR_DeleteExtState('pyperclip', 'copy', False)
It seems to work pretty good (at least for my tasks).
Many thanks to cfillion and Xenakios!
|
|
|
Thread Tools |
|
Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -7. The time now is 01:33 PM.
|