Old 03-09-2017, 09:53 PM   #1
Lokasenna
Human being with feelings
 
Lokasenna's Avatar
 
Join Date: Sep 2008
Location: Calgary, AB, Canada
Posts: 6,551
Default Script: Create action to open a file...

As per @hopi's request here: http://forum.cockos.com/showthread.php?t=189037

Allows you to browse for a file (or a folder) and then generates a ReaScript to open it in the appropriate app. Could be used for folders you frequently access, or filling a toolbar with shortcuts to the manuals for your favorite plugins, etc, etc.

Available on ReaPack, or manually: Lokasenna_Create action to open a file... .lua

Enjoy.
__________________
I'm no longer using Reaper or working on scripts for it. Sorry. :(
Default 5.0 Nitpicky Edition / GUI library for Lua scripts / Theory Helper / Radial Menu / Donate
Lokasenna is offline   Reply With Quote
Old 03-09-2017, 11:55 PM   #2
hopi
Human being with feelings
 
hopi's Avatar
 
Join Date: Oct 2008
Location: Right Hear
Posts: 15,618
Default

oh no... REALLY? Holy Smoke.... I'm too gone to try that tonight but I am mucho excited to give that go... you are amazing!!!
__________________
...should be fixed for the next build... http://tinyurl.com/cr7o7yl
https://soundcloud.com/hopikiva
hopi is offline   Reply With Quote
Old 03-10-2017, 02:52 AM   #3
IXix
Human being with feelings
 
Join Date: Jan 2007
Location: mcr:uk
Posts: 3,889
Default

Quote:
Originally Posted by Lokasenna View Post
Allows you to browse for a file (or a folder) and then generates a ReaScript to open it in the appropriate app.
Ha, show-off!
IXix is offline   Reply With Quote
Old 03-10-2017, 10:00 AM   #4
hopi
Human being with feelings
 
hopi's Avatar
 
Join Date: Oct 2008
Location: Right Hear
Posts: 15,618
Default

Ok ...so tested and it's pretty insane that it works as it does...

and yet, it makes me ask this:

Can we have one that does the same thing but does not go to the individual file level? In other words, it will just let us choose a given folder to open and save that as a new script?
__________________
...should be fixed for the next build... http://tinyurl.com/cr7o7yl
https://soundcloud.com/hopikiva
hopi is offline   Reply With Quote
Old 03-10-2017, 08:59 PM   #5
Lokasenna
Human being with feelings
 
Lokasenna's Avatar
 
Join Date: Sep 2008
Location: Calgary, AB, Canada
Posts: 6,551
Default

Read the first message that pops up.

Reaper doesn't give me a way to pop up a "Choose a folder" dialog. Or a "Save As" dialog, for that matter.
__________________
I'm no longer using Reaper or working on scripts for it. Sorry. :(
Default 5.0 Nitpicky Edition / GUI library for Lua scripts / Theory Helper / Radial Menu / Donate
Lokasenna is offline   Reply With Quote
Old 03-10-2017, 09:14 PM   #6
Lokasenna
Human being with feelings
 
Lokasenna's Avatar
 
Join Date: Sep 2008
Location: Calgary, AB, Canada
Posts: 6,551
Default

Updated, automatically adds the new script to the Action List.
__________________
I'm no longer using Reaper or working on scripts for it. Sorry. :(
Default 5.0 Nitpicky Edition / GUI library for Lua scripts / Theory Helper / Radial Menu / Donate
Lokasenna is offline   Reply With Quote
Old 03-10-2017, 10:47 PM   #7
hopi
Human being with feelings
 
hopi's Avatar
 
Join Date: Oct 2008
Location: Right Hear
Posts: 15,618
Default

ummm OK thanks for explaining this....

It is indeed quite amazing that it can open a given file and automatically write the new script...

At the same time it is not all that useful for me to open a 'file'... I need to open a folder... without leaving being inside reaper...

hmmm.... I wonder if it would open a shortcut.... I'll test that in a moment
__________________
...should be fixed for the next build... http://tinyurl.com/cr7o7yl
https://soundcloud.com/hopikiva
hopi is offline   Reply With Quote
Old 03-11-2017, 04:55 AM   #8
sonicowl
Human being with feelings
 
sonicowl's Avatar
 
Join Date: Oct 2015
Posts: 739
Default

hopi, just delete filename, and leave only folder path. Then it opens folder.
sonicowl is offline   Reply With Quote
Old 03-11-2017, 07:10 AM   #9
Lokasenna
Human being with feelings
 
Lokasenna's Avatar
 
Join Date: Sep 2008
Location: Calgary, AB, Canada
Posts: 6,551
Default

Quote:
Originally Posted by sonicowl View Post
hopi, just delete filename, and leave only folder path. Then it opens folder.
Like the first message box says.

Seriously though, if the wording there is unclear I'm open to suggestions for a better way to phrase it.
__________________
I'm no longer using Reaper or working on scripts for it. Sorry. :(
Default 5.0 Nitpicky Edition / GUI library for Lua scripts / Theory Helper / Radial Menu / Donate
Lokasenna is offline   Reply With Quote
Old 03-11-2017, 12:32 PM   #10
IXix
Human being with feelings
 
Join Date: Jan 2007
Location: mcr:uk
Posts: 3,889
Default

Quote:
Originally Posted by Lokasenna View Post
Updated, automatically adds the new script to the Action List.
Now come on, that really is just showing off! For goodness sake man, tone it down. You're making the rest of us look bad!
IXix is offline   Reply With Quote
Old 03-11-2017, 12:39 PM   #11
Lokasenna
Human being with feelings
 
Lokasenna's Avatar
 
Join Date: Sep 2008
Location: Calgary, AB, Canada
Posts: 6,551
Default

Quote:
Originally Posted by IXix View Post
Now come on, that really is just showing off! For goodness sake man, tone it down. You're making the rest of us look bad!
It was a suggestion from mpl, but thanks.
__________________
I'm no longer using Reaper or working on scripts for it. Sorry. :(
Default 5.0 Nitpicky Edition / GUI library for Lua scripts / Theory Helper / Radial Menu / Donate
Lokasenna is offline   Reply With Quote
Old 03-12-2017, 02:05 AM   #12
hopi
Human being with feelings
 
hopi's Avatar
 
Join Date: Oct 2008
Location: Right Hear
Posts: 15,618
Default

Keep showing off!

I think I totally misunderstood at first but now I maybe get it...

You guys are saying run the script, then edit the lua it creates by taking out the file name... and that will open the folder.... gotta go test but if that is it, that will suit me just great.
__________________
...should be fixed for the next build... http://tinyurl.com/cr7o7yl
https://soundcloud.com/hopikiva
hopi is offline   Reply With Quote
Old 03-12-2017, 09:05 AM   #13
Lokasenna
Human being with feelings
 
Lokasenna's Avatar
 
Join Date: Sep 2008
Location: Calgary, AB, Canada
Posts: 6,551
Default

You can remove the filename in the window that lets you provide an alias for the script.
__________________
I'm no longer using Reaper or working on scripts for it. Sorry. :(
Default 5.0 Nitpicky Edition / GUI library for Lua scripts / Theory Helper / Radial Menu / Donate
Lokasenna is offline   Reply With Quote
Old 03-12-2017, 06:15 PM   #14
timbralzoom
Human being with feelings
 
timbralzoom's Avatar
 
Join Date: Apr 2010
Location: Turkey/Istanbul
Posts: 1,820
Default

Very useful, Thank you so much!
timbralzoom is offline   Reply With Quote
Old 03-17-2017, 07:31 PM   #15
Lokasenna
Human being with feelings
 
Lokasenna's Avatar
 
Join Date: Sep 2008
Location: Calgary, AB, Canada
Posts: 6,551
Default

Small update, courtesy of @mpl. It will now use the filename you select as a suggested alias.
__________________
I'm no longer using Reaper or working on scripts for it. Sorry. :(
Default 5.0 Nitpicky Edition / GUI library for Lua scripts / Theory Helper / Radial Menu / Donate
Lokasenna is offline   Reply With Quote
Old 10-24-2017, 04:06 AM   #16
Stroudy
Human being with feelings
 
Stroudy's Avatar
 
Join Date: Jul 2014
Location: London
Posts: 733
Default

Would love to use this, but all the files are greyed out for me. Is this a mac problem?
Stroudy is offline   Reply With Quote
Old 10-26-2017, 03:35 PM   #17
Lokasenna
Human being with feelings
 
Lokasenna's Avatar
 
Join Date: Sep 2008
Location: Calgary, AB, Canada
Posts: 6,551
Default

I... have no idea.
__________________
I'm no longer using Reaper or working on scripts for it. Sorry. :(
Default 5.0 Nitpicky Edition / GUI library for Lua scripts / Theory Helper / Radial Menu / Donate
Lokasenna is offline   Reply With Quote
Old 10-27-2017, 01:17 AM   #18
amagalma
Human being with feelings
 
amagalma's Avatar
 
Join Date: Apr 2011
Posts: 3,451
Default

Lokasenna, I hope you don't mind me posting this..

Code:
--[[
Description: Create action to open a file...
Version: 1.2.2
Author: Lokasenna
Donation: https://paypal.me/Lokasenna
Changelog:
	Name change for consistency
Links:
	Forum Thread http://forum.cockos.com/showthread.php?t=189152
	Lokasenna's Website http://forum.cockos.com/member.php?u=10417
About: 
	Automates the creation of ReaScripts that will open files or folders
	in their native app. Handy for shortcuts to plugin manuals, or commonly
	used folders, etc.
	
	Note: Due to Reaper limitations, creating a shortcut to a folder equires you
		  to select a file IN that folder, and then manually erase the filename
		  from the path. Sorry. :/
--]]

-- Licensed under the GNU GPL v3

local ret, path, csv, alias

reaper.ShowMessageBox("To create an action that opens a folder:\n\n1. Use the next window to select a file in that folder.\n2. Click 'OK'.\n3. Another window will pop up; manually erase the filename there.\n\nThis is a Reaper limitation - sorry for the inconvenience.", "Create action to open a file...", 0)

ret, path = reaper.GetUserFileNameForRead("", "Select a file", "")
if not ret then return 0 end

-- Cheers to @mpl for this.
local num = path:reverse():find('[%/%\\]')
local alias = path:sub(-num + 1) .. " "
	--reduced_name = reduced_name:sub(0,-1-reduced_name:reverse():find('%.')) -- cut extension also


ret, csv = reaper.GetUserInputs("Create action to open a file... ", 2, "File/folder path:,File alias:,extrawidth=128", path..","..alias)
if not ret or csv == "" then return 0 end

path, alias = string.match(csv, "([^,]+),([^,]*)")
if not path then return 0 end

local str =  "-- Created with Lokasenna_Create action to open a file... .lua\n"
		.. 'local path = "' .. path .. '"\n'
		.. [[if string.match( reaper.GetOS(), "Win") then]] .. "\n"
		.. [[  reaper.ExecProcess('cmd.exe /C start "" "' .. path ..'"', 0)]]
		.. "\nelse\n"
		.. [[  os.execute('open "" "' .. path)]] .. "\n"
		.. "end\n"
		.. "reaper.defer(function () end)"
str = string.gsub(str, [[\]], [[\\]])

local info = debug.getinfo(1,'S');
local script_path = info.source:match[[^@?(.*[\/])[^\/]-$]]
local file_name = script_path .. "Open a file - " .. alias .. ".lua"

local file, err = io.open( file_name , "w+")
if not file then
	reaper.ShowMessageBox("Couldn't create file:\n" .. file_name .. "\n\nError: " .. tostring(err), "Whoops", 0)
	return 0
end

file:write(str)

reaper.ShowMessageBox( "Successfully created file:\n" 
					.. ( string.len(file_name) > 64 and ( "..." .. string.sub(file_name, -56) ) 
													or      file_name), 
						"Yay!", 0)

io.close(file)

reaper.AddRemoveReaScript( true, 0, file_name, true )
A very slightly modified version.. For Windows, it doesn't open the command prompt. Also, (for any OS) the script doesn't create an undo point in the Undo History
__________________
Most of my scripts can be found in ReaPack.
If you find them useful, a donation would be greatly appreciated! Thank you! :)
amagalma is offline   Reply With Quote
Old 01-23-2018, 12:21 PM   #19
X-Raym
Human being with feelings
 
X-Raym's Avatar
 
Join Date: Apr 2013
Location: France
Posts: 9,874
Default

Just noticed this script... A script which generate a script. Nice concept ^^
X-Raym is offline   Reply With Quote
Old 08-05-2019, 04:21 AM   #20
Phazma
Human being with feelings
 
Join Date: Jun 2019
Posts: 2,872
Default

Can't get this script to work, I can only navigate through the folders but the files are all greyed out.
Phazma is offline   Reply With Quote
Old 08-05-2019, 06:33 AM   #21
Lokasenna
Human being with feelings
 
Lokasenna's Avatar
 
Join Date: Sep 2008
Location: Calgary, AB, Canada
Posts: 6,551
Default

Quote:
Originally Posted by Phazma View Post
Can't get this script to work, I can only navigate through the folders but the files are all greyed out.
That's strange. What OS?
__________________
I'm no longer using Reaper or working on scripts for it. Sorry. :(
Default 5.0 Nitpicky Edition / GUI library for Lua scripts / Theory Helper / Radial Menu / Donate
Lokasenna is offline   Reply With Quote
Old 08-05-2019, 06:40 AM   #22
Phazma
Human being with feelings
 
Join Date: Jun 2019
Posts: 2,872
Default

Quote:
Originally Posted by Lokasenna View Post
That's strange. What OS?
macOS High Sierra
Phazma is offline   Reply With Quote
Old 08-12-2019, 03:52 PM   #23
Lokasenna
Human being with feelings
 
Lokasenna's Avatar
 
Join Date: Sep 2008
Location: Calgary, AB, Canada
Posts: 6,551
Default

Turns out it's a Reaper issue, which should be fixed as of today's prerelease (v5.981+dev0812). You can test that version if you want, or wait a week or two for the next official release - in either case, let me know if the problem doesn't go away.
__________________
I'm no longer using Reaper or working on scripts for it. Sorry. :(
Default 5.0 Nitpicky Edition / GUI library for Lua scripts / Theory Helper / Radial Menu / Donate
Lokasenna is offline   Reply With Quote
Old 08-13-2019, 12:26 AM   #24
Phazma
Human being with feelings
 
Join Date: Jun 2019
Posts: 2,872
Default

Quote:
Originally Posted by Lokasenna View Post
Turns out it's a Reaper issue, which should be fixed as of today's prerelease (v5.981+dev0812). You can test that version if you want, or wait a week or two for the next official release - in either case, let me know if the problem doesn't go away.
Thanks for the info! The creation of the action now works flawlessly, however running the action does not do anything. Could it be that this script has been made for windows?
I have no clue about scripting, however when opening the script I can see it says reaper.GetOS(), "Win" at a certain point.. could this refer to windows?
Phazma is offline   Reply With Quote
Old 08-13-2019, 06:30 AM   #25
Lokasenna
Human being with feelings
 
Lokasenna's Avatar
 
Join Date: Sep 2008
Location: Calgary, AB, Canada
Posts: 6,551
Default

It checks to see if the user is on Windows versus Mac so it can use the appropriate terminal command - start on Windows, open on Mac.
Code:
reaper.GetOS(), "Win") and ('start "" "') or ('open "" "')
I could swear I've had a couple of people use it on Mac without any trouble.

- Does it give an error, or just do nothing at all?
- Are you able to find the script it created for the file you chose? The script will be in the same folder as the main script, so ReaScripts/Various/Open a file - ______.lua. If so, open it in a text editor and paste the contents here.

I did just discover that it doesn't work on Linux though. :P
__________________
I'm no longer using Reaper or working on scripts for it. Sorry. :(
Default 5.0 Nitpicky Edition / GUI library for Lua scripts / Theory Helper / Radial Menu / Donate

Last edited by Lokasenna; 08-13-2019 at 06:42 AM.
Lokasenna is offline   Reply With Quote
Old 08-13-2019, 10:50 AM   #26
Phazma
Human being with feelings
 
Join Date: Jun 2019
Posts: 2,872
Default

It just does nothing at all.
Here is the text from the script it created:
-- Created with Lokasenna_Create action to open a file... .lua
os.execute( ( string.match( reaper.GetOS(), "Win") and ('start "" "') or ('open "" "') ) .. "/Users/mirko/Library/Application Support/REAPER/ Reaper Media/Manuals/USER GUIDE.pdf" )
Phazma is offline   Reply With Quote
Old 08-13-2019, 11:02 AM   #27
Lokasenna
Human being with feelings
 
Lokasenna's Avatar
 
Join Date: Sep 2008
Location: Calgary, AB, Canada
Posts: 6,551
Default

What happens if you open a terminal and put in:
Code:
open "" "/Users/mirko/Library/Application Support/REAPER/ Reaper Media/Manuals/USER GUIDE.pdf"
?
__________________
I'm no longer using Reaper or working on scripts for it. Sorry. :(
Default 5.0 Nitpicky Edition / GUI library for Lua scripts / Theory Helper / Radial Menu / Donate
Lokasenna is offline   Reply With Quote
Old 08-13-2019, 11:57 AM   #28
Phazma
Human being with feelings
 
Join Date: Jun 2019
Posts: 2,872
Default

Quote:
Originally Posted by Lokasenna View Post
What happens if you open a terminal and put in:
Code:
open "" "/Users/mirko/Library/Application Support/REAPER/ Reaper Media/Manuals/USER GUIDE.pdf"
?
It opens the finder (home folder) as well as the correct file which it is supposed to open.
Phazma is offline   Reply With Quote
Old 02-11-2021, 08:29 AM   #29
o_e
Human being with feelings
 
o_e's Avatar
 
Join Date: May 2016
Posts: 681
Default

Quote:
Originally Posted by Phazma View Post
It opens the finder (home folder) as well as the correct file which it is supposed to open.
Try:
Code:
os.execute('open -a "Preview" "/Users/mirko/Library/Application Support/REAPER/ Reaper Media/Manuals/USER GUIDE.pdf"')
o_e is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -7. The time now is 02:14 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.