Real Software Forums
http://forums.realsoftware.com/

How does App get launchd ProgramArguments?
http://forums.realsoftware.com/viewtopic.php?f=7&t=47933
Page 1 of 1

Author:  Tom Baumgartner [ Tue May 21, 2013 5:57 am ]
Post subject:  How does App get launchd ProgramArguments?

There is a gap in my understanding of how launchd and Xojo (might as well get used to the new name) communicate.

If my launchd plist is:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC -//Apple Computer//DTD PLIST 1.0//EN http://www.apple.com/DTDs/PropertyList-1.0.dtd >
<plist version="1.0">
<dict>
<key>Label</key>
<string>myApp Launcher</string>
<key>ProgramArguments</key>
<array>
<string>~/Applications/myApp</string>
<string>-f</string>
</array>
.....


How do I get my app to receive the "-f" program argument when it is started by launchd?

Author:  JeremK [ Wed May 22, 2013 6:48 am ]
Post subject:  Re: How does App get launchd ProgramArguments?

Hello,

The app gets the ProgramArguments using the "System.CommandLine" property.

This is the code I use in one of my programs.
The command() property then has all commands sent to the App.

Dim commands() As String
Dim FoundQuote As Boolean
Dim SplitCommand() As String
SplitCommand = Split((Trim(System.CommandLine).Replace(chr(34) + " " + chr(34), chr(34) + chr(34))), "")
Dim index As Integer
Dim tempStr As String

//List of commands
// -w #### : output width
// -h #### : output height
// -r simple | browser | smart | border : resize type
// -nostop : do not display error messages
// -bfontsize ## : output text size in browser

For each letter as String in SplitCommand
Select case letter
Case " "
If not FoundQuote then
index = index + 1
commands.Append tempStr
tempStr = ""
else
tempStr = tempStr + letter
End If
Case chr(34)
If not FoundQuote then
commands.Append tempStr
tempStr = ""
End If
FoundQuote = not FoundQuote
else
tempStr = tempStr + letter
End Select
Next
commands.Append tempStr

commands.Remove(1)

Page 1 of 1 All times are UTC - 5 hours
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/