Script to open a pdf file

Try using forward slashes instead of backslashes for the PdfViewerPath.
PdfViewerPath = “D:/Markus/OneDrive/GigPerformer/bin/SumatraPDF.exe”

2 Likes

Oh no… :man_facepalming:

As a Windows user I am so used to backslashes in paths, that I didn’t realize the forward ones in all the above examples.

Thank you so much!

It’s an easy thing to overlook. Have done it myself a few times over the years copy/pasting windows file paths into xml files, only to realize that it requires forward slashes.

Yeah, this is a problem that goes all the way back to DOS. Microsoft used the forward slash to separate command line arguments (paths hadn’t even been invented) and so when they got around to supporting paths they used the backslash. The problem is that most programming languages use a backslash as an “escape” prefix to insert otherwise non-visible characters into a string and so can’t be used by themselves to define paths. Fortunately, internally, the Windows APIs support the use of regular forward slashes as path separators.

Interesting to hear this explanation after all these years. I always wondered, why Windows- and Unix-path separators differ.
Strange, though, to imagine that there has been a time without paths. :sweat_smile:

Somewhere I found a webpage with an emulation of old Windows versions. I could not believe, that Windows 1.0 was all in the root directory without any folders. :open_mouth:

In this post, David mentions he triggers a shellscript from Gig Performer. I have done quite a lot of scripting now, but I haven’t been able to get neither “Shell” nor “EA_Start” right.
All I want to do is trigger some application with a widget but the following doesn’t work:

var
   WIDGET : Widget

On WidgetValueChanged (newValue : Double) from WIDGET
   Shell("open /Applications/Safari.app")
End

(Safari is just an example.) What simple thing am I missing here?

Best regards,
Florian

You are on Mac, right?

Try this:

//$<AutoDeclare>
// DO NOT EDIT THIS SECTION MANUALLY
Var
   BUTTON : Widget
   Ext_App : ExternalApplication
//$</AutoDeclare>


// Called when a single widget value has changed
On WidgetValueChanged(newValue : double) from BUTTON
 if newValue == 1.0 then
  EA_SetProgramName(Ext_App, "open")
  EA_ClearAllArgs(Ext_App)
  EA_AddArgument(Ext_App,"-n")
  EA_AddArgument(Ext_App,"/Applications/Safari.app") 
  EA_Start(Ext_App)
 end 
End

True, on a Mac.
The script you posted, @pianopaul, does work and I’m glad you showed me how to use the EA_… function. Thank you very much for that! :+1:

To learn even more, could you please give me a hint what is wrong in my try using the Shell function?
This (according to the manual)

var
   WIDGET : Widget

On WidgetValueChanged (newValue : Double) from WIDGET
   Shell("open /Applications/Safari.app")
End

is returning that:
“Semantic error/ No assignment found for function that returns a value”.

Thanks to this great community!

Shell is a function which returns an Integer value:

//$<AutoDeclare>
// DO NOT EDIT THIS SECTION MANUALLY
Var
   BUTTON : Widget
   command : Integer
//$</AutoDeclare>


// Called when a single widget value has changed
On WidgetValueChanged(newValue : double) from BUTTON
 if newValue == 1.0 then
  command = Shell("open -n /Applications/Safari.app")
 end 
End
3 Likes

As @pianopaul mentioned, you have to look out for whether the function returns something. If so, you must account for that in your code, even if you don’t do anything with the returned value.

Shell(command ) Autotype

Run an OS Shell command (Mac only) returning an integer indicating success or failure

2 Likes

Thank you both for this good explanation. :ok_hand: :grinning:

1 Like

It’s been a while since I started this thread! I’ve purchased GP4 and was wondering if there are any code changes that would make things easier. My goal is this:

In a setlist, when a song is called up I would like to trigger my main PDF program to bring up the song title. Has anything changed that would make my code better?

Thanks!

Yeah, my old script doesn’t work anymore and I’ve completely forgot how to use GP Script. Any help appreciated. Thanks!

Now you can download the PDF to ChordPro tool. See more information here: PDFToGPChordPro

1 Like

Well, I gave it a try, but

a) I got a “No such file or directory” error. I tried moving the directory to someplace more simple. I tried changing the \ to /. No joy.

b) The script I wrote (above) worked great without all of that conversion work. I just need some help with a new script since GP has changed.

Any help? :pleading_face:

More details please - what exactly did you do? the new PDFToGPChordPro works pretty well and lets you use the ChordPro system … it should work for you

I followed the instructions exactly. I dropped the PDF into PDFToGPChordPro. It converted it into two png images. I opened the Song/Lyrics Chords window. I clicked the Edit tab I pasted:



{songpartname: 1}
{image: "D:/Defaults/Documents/PDFs/There's Nothing That God Can't Do/There's Nothing That God Can't Do-000001.png" }

{songpartname: 2}
{image: "D:/Defaults/Documents/PDFs/There's Nothing That God Can't Do/There's Nothing That God Can't Do-000002.png" }

I got the error.

However… again… Since I already have a ton of PDFs and could just add a scriptlet to each song to pull up the PDF… that would be so much easier. I will either:

  1. Try to figure out how to write the script I need myself or
  2. Abandon GP and keep using Cantabile, which easily pulls up my PDFs with a command line containing a variable for the song or rack name. I don’t have to do anything after creating the binding. The PDF loads right up.

Switching from Cantabile to GP is no easy task. I’ve been using Cantabile for several years. It’s going to take weeks to transfer my patches. I really want to use the more visual interface offered by GP, but if I can’t do something as simple as pulling up a PDF (something I wrote in a working script a while back) then I’m hesitant.

To be clear, I don’t want to use PDFToGPChordPro since a scriptlet would be so much easier.

But just so you know and maybe can tell me what’s wrong, here’s more about the error in this screenshot:

Are you sure you’re using Gig Performer 4.1.5?

Just installed yesterday, but I checked and yes, 4.1.5.

This is the code from 2018. I can re-learn the script. Just looking for a shortcut.

//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