Script to open a pdf file

Hi! I’m trial-ing Gig Performer and don’t have time to dig into the scripting. One feature I need: When I move to a song (rackspace), I need to trigger a PDF file specific to that song. That PDF is my chord chart. If I can use the song title as a variable that would be even better.

I’m doing this in a competitor’s program and it works well, but that program doesn’t have the patch persist or pre-load feature, which is pretty cool. Any help is appreciated.

Currently, there’s really no way to do that without using scripting to leverage the “shell” function to get your machine to run a PDF viewer, say. And the details differ depending on whether you’re on a PC or a Mac.

Having said that, most people tend to do this the other way around. For example, some people use an iPad to run a setlist sheet music manager (such as forScore) which can send out program changes to Gig Performer when you select your song. That’s how I do it. Setlist manager and its big brother, Band Helper are other examples.

There are also several sheet music setlist programs that run directly on Macs and PCs and they can generally send out program changes as well.

My own approach is to drive Gig Performer directly while developing sounds/rackspaces and so forth but when I’m on stage, it essentially becomes a “server” controlled from keyboards or guitar pedal boards or by a separately running set list manager or even via OSC for remote control and I never go near the laptop.

Other users might have other thoughts.

I’m trying to avoid using more than one device. The other guys in the band use iPads for their music. Since I’m already using a convertible PC for my sounds, I figure I should use it for the music as well. Plus I get double the real estate and I don’t have to switch between pages. It’s what I’m doing now and want to keep it that way…

So, if it can be done with a script, is it easy? All I need it to do is call up a file (through a shell is fine). My computer already associates PDFs with my favorite viewer, so that’s not an issue. I just don’t know the syntax. The file location would probably be something like, “c://users/me/documents/pdfs/$rackspacetitle.pdf”

Unfortunately, on Windows it’s not that easy. GP Script exposes a collection of functions (they all start with EA_, meaning ExternalApplication) to execute external programs but, for example, while you could open a PDF on Windows (and I’ve no idea if you could just “open” on Windows, you might need the full path to the executable), you can’t close it easily so you’d end up with a bunch of open PDF files.

I’ve experimented with this a bit on a Mac using Applescript from inside Gig Performer’s GP Script but I didn’t really find it to be practical.

We’ll probably address this directly at some point but right now I don’t think it’s practical to drive a PDF application from Gig Performer. I hate to drive away potential users but I’d much rather you buy something else than get our system and be unhappy that it doesn’t do what you need.

Let me take one more run at this ;-). The reason I’m looking into Gig Performer is because it pre-loads songs and has patch persist. That’s one thing my current host doesn’t have. Opening PDF files is a perk, but it saves me prep time. It’s no big deal if GP doesn’t close the PDFs (my current host doesn’t either). They all just open in the same program. If the PDF is opened a second time, it doesn’t open a second copy, it just goes back to the original PDF. There’s no need to call up the executable because I’ve associated all PDFs with my favorite PDF program. When a PDF is opened, so does the executable.

So… is there a script that will open a file when a song is loaded?

Well, I have to say I just astonished myself! I’ve done all my GP scripting on a Mac but I just ran GP on a Windows machine and wrote the script below and discovered that I could actually have Adobe Acrobat open with a PDF file when the rackspace is activated and then close again when you go to another rackspace. I didn’t really expect this to work :slight_smile: and I can’t guarantee it will work with other applications. However, you could always use the technique to run a PowerShell file that does the heavy lifting.

Note - the association of PDFs with an application is not relevant here. That automatic “association” won’t (currently) work using the mechanism GP Script uses to invoke external programs, although I’ll have to take a look at some point to see if it will work

You’ll have to duplicate the code below in every rackspace (just changing the file name) for now as there’s no notion of a global script at this time. Alternatively, you could create a second instance of gig performer with a single rackspace that has a script that responds to a MIDI callback so you could, for example, send MIDI messages from your main instance into the second instance (or use OSC messages) and make a script respond.

var
   reader : ExternalApplication // A GPScript object used to execute an external application. This object MUST be declared at global scope
   
   pdfApplicationName : string // This will hold the full name of the application used
                                // to open a PDF file
   
initialization
   // Need to keep the name of the application. File associations won't work
   pdfApplicationName = "C:/Program Files (x86)/Adobe/Acrobat Reader DC/Reader/AcroRd32.exe"
   
   
end

// A GP Script function to handle the gory details
function OpenPDFFile(var name : string)
   reader.EA_ClearAllArgs()
   reader.EA_AddArgument(pdfApplicationName)  // First arg is always the name of the executable to run

   reader.EA_AddArgument(name)  // This should be the PDF filename
   reader.EA_Start()  // Run the executable

end

On Activate
   // Opens PDF in Acrobat reader
   OpenPDFFile("C:/Users/dhj/ownCloud/ReelingInTheYears/Josie/Josie - Proof 2.pdf")

End

On Deactivate
   // Closes acrobat reader
   reader.EA_Stop()
end
1 Like

OKAY! Thanks so much for the code! The problem I had was that the app I use for reading charts (Xodo) is a Windows App – and you can’t open it from a script for some reason (stupid Win permissions). If I use Adobe Reader, the PDF isn’t full-screen or 2 page, etc. So I modified your code to open files with Windows PowerShell. With this script, it WILL open programs based on file associations. It will also open web addresses. It should open any file type – even executables, I’m guessing. In my example below, it opens my PDF in Xodo and also opens the website I use to practice with using my default browser. I couldn’t have done it without your code, so THANK YOU!!!

Feel free to post this code or use it or whatever. :slight_smile:

//Script to open a file or website location when a song/rackspace is opened. Uses Windows PowerShell. 
//This will open the program associated with the file-type, but will not close the program when deactivating the song/rackspace.

var
   file : ExternalApplication // A GPScript object used to execute an external application. This object MUST be declared at global scope
   
   PowerShell : string // This will hold the full name of the application used
                                // to open a file or web link
   
initialization
   // Location of PowerShell
   PowerShell = "C:/Windows/System32/WindowsPowerShell/v1.0/powershell.exe"
   
   
end

// A GP Script function to handle the gory details
function OpenFile(var name : string)
   file.EA_ClearAllArgs()
   file.EA_AddArgument(PowerShell)  // First arg is always the name of the executable to run

   file.EA_AddArgument(name)  // This should be location of a file or web address
   file.EA_Start()  // Run the executable

end

On Activate
   // Opens file or link in PowerShell. Use 'C:/path/to/file.ext' or 'http://website.com/'
   // The file or link will be opened by the program associated with it.
   //You can use multiple OpenFile commands for multiple files or links.
   OpenFile("start 'C:/Users/music/Documents/PDFs/Your Love Awakens Me.pdf'")
   OpenFile("start 'https://www.multitracks.com/'")

End

//Following is left over code not necessary because PowerShell runs in the background and closes itself.
//On Deactivate

   //file.EA_Stop()
//end

Yeah, that is something I have done on the Mac, i.e, just use Gig Performer to trigger a shellscript which then does the heavy lifting. When I implemented that external process object, I wasn’t really thinking about how it might be used, I just figured it MIGHT be convenient to be able to trigger some external program. Now that I’ve seen this usage, I’m going to modify that object so that you can specify a program name explicitly rather than just using the first argument as the program name. That way, it will be feasible to use the ClearAllArgs to JUST replace the arguments and with no need to keep reassigning the program name.

Glad it worked out for you though. Enjoy Gig Performer

:slight_smile: Great idea! And thanks, I’m getting to know it a bit better.

Yeah, I’ve added a function called EA_SetProgramName() to do this - it will be in the next release.

Very cool!

It’s been a while, since you have been discussing this. Your research saves me a lot of time today. Thanks a lot!
Does anyone know a PDF-Viewer that receives OSC-Messages? Would be cool, if the pages could be turned via GPscript.

Are you on Mac?

No, I am a Windows user. Sorry, I forgot to mention.

Ok, on Mac I could imagine a solution with OSCulator and Automator…
On Windows I do not know…

Okay, that’s what I feared, when you asked about my OS. :sweat_smile:
Thanks anyway!

May that helps
https://www.bome.com/products/miditranslator

Incoming Actions

MIDI messages
keystrokes
timer
enable/disable the current preset
opening a project file
bytes or text on a serial port

Processing (“Rules”)

A sequence of rules can be defined to be processed if the incoming action matches:

assignments of variables, e.g. pp = 20
simple expressions, e.g. pp = og + 128
labels and goto, e.g. goto "2nd Options"
conditional execution, e.g. IF pp < 20 THEN do not execute Outgoing Action

Outgoing Actions

MIDI messages
keystrokes
mouse movements
create/start/stop timer
change active preset
enable/disable the current preset
execute program
send bytes or text to serial ports
1 Like

Yes, this would be a workaround. I even remember to have seen a free MIDI2keystroke tool somewhere. I will definitely experiment with this.
Thanks! :handshake:

I found a better solution with a lightweight pdf viewer called SumatraPDF. It has a bunch of command line options like:
-fullsreen
-page [number]
-reuse-instance

Especially the last one comes in handy, when you just want to turn pages from within gpscript.

Well now I am really confused. I try to declare this SumatraPDF as external application, but already fail when assigning the path to a string variable… :astonished:

image

First thing I notice is that the type “ExternalApplication” in the declarations is not highlighted. Double checked the spelling and even removed the line. But the error remains.
Already tried to use different quotes: " ’ `
Nothing helps.

What am I doing wrong? Can anyone enlighten me?