I've been struggling with this for quite a long time now (weeks?) and
figure it's time to get some advice from folks that know what they're
doing.
Essentially, I am trying to launch an OSX GUI application (The Adobe
Flash Player) from a ruby process, send this new process a file target
to open, and keep a handle to this process so that I can find out when
it exits, or even force it to exit in some circumstances.
I have had no trouble at all performing this task in the Windows XP
Shell and Cygwin, but OS X is giving me much heartache.
The Flash Player does not read or write to standard in, standard out
or standard error, so I'm not sure if popen is really the way to go or
not.
If you're going to try this at home, you'll need three things:
1) A SWF File
2) The desktop debug Flash Player for OS X
3) The attached ruby script
Unfortunately, I'm not allowed to distribute the Flash Player, so
you'll have to grab it from here:
http://tinyurl.com/yuly87
or
http://download.macromedia.com/pub/flashplayer/updaters/9/sa_flashplayer_9_all_debug_ub.dmg
You can download the ruby script and a swf file from here:
http://www.asserttrue.com/files/Published.zip
(I have also included the latest script below)
The behavior that I'm getting is as follows:
a) If I use the recommended OS X 'open -a' command against the "Flash
Player.app" folder/executable, the Flash Player opens, takes focus and
displays the SWF file perfectly, but I lose all references to the
spawned process in ruby. So I can't tell when it closes or force it to
close when I want it to.
b) If I use sh, exec, system or popen, I cannot target the .app folder
but instead must point at "Flash Player.app/Content/MacOS/standalone".
This approach will launch the Flash Player and keep a handle to it in
ruby so that the processes are perfectly tied, but I can't seem to
send in the target to the SWF file.
I'm pretty sure there is a simple fix to this problem, but I can't
seem to find it anywhere. Any help would be greatly appreciated.
Thanks,
Luke Bayes
lbayes [at] p a t t e r n p a r k [dot] com
www.asunit.org
File: flash_player.rb
----------------8<------------------
class FlashPlayer
def initialize
# This will launch the Player with the swf
# but I cannot hold onto the process because
# 'open' seems to fork and I'm not sure how
# to grab the forked process id...
execute_with_open
# This will launch the player and hold onto
# the process, but I can't get it to accept
# the requisite swf file
#execute_without_open
end
def execute_with_open
player = "Flash\ Player.app"
swf = "Published.swf"
IO.popen("open -a '#{player}' #{swf}") do |p|
puts 'Player opened'
end
puts 'Player thread returned'
end
def execute_without_open
player = "Flash\ Player.app/Contents/MacOS/standalone"
swf = "Published.swf"
t = Thread.new {
IO.popen("'#{player}' #{swf}") do |p|
puts 'Player opened - but not focused?'
end
}
while(t.alive?)
sleep(0.3)
puts 'Player still open'
end
puts 'Player closed'
end
end
FlashPlayer.new
---------------->8------------------