Can I determine if another application is running?
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
Can I determine if another application is running?
Hi,
For a little app launching utility I am building in Runrev, it would be useful if I could determine if an application, such as Apple Mail, is running or not. Is there a way to do this in Rev? The OpenProcesses only seems to return processes opened by Rev, not applications launched in the Finder. Any help would be much appreciated.
Thanks
Bob Arnold
For a little app launching utility I am building in Runrev, it would be useful if I could determine if an application, such as Apple Mail, is running or not. Is there a way to do this in Rev? The OpenProcesses only seems to return processes opened by Rev, not applications launched in the Finder. Any help would be much appreciated.
Thanks
Bob Arnold
-
- Livecode Opensource Backer
Re: Can I determine if another application is running?
You have to use applescript or run a command over the shell. Look under shell in the doc.rfarnold wrote:The OpenProcesses only seems to return processes opened by Rev, not applications launched in the Finder. Any help would be much appreciated.
Code: Select all
put shell("ps -x") into tProcessesOnMyMac
if offset ("/Mail.app/", tProcessesOnMyMac) > 0 then
answer "mail is open"
end if
Can I determine if another application is running
You have to use applescript or run a command over the shell. Look under shell in the doc.
Code: Select all
put shell("ps -x") into tProcessesOnMyMac
if offset ("/Mail.app/", tProcessesOnMyMac) > 0 then
answer "mail is open"
end if
Code: Select all
PID TT STAT TIME COMMAND
76 ?? Ss 1:01.41 /System/Library/Frameworks/ApplicationServices.framew
77 ?? Ss 0:01.46 /System/Library/CoreServices/loginwindow.app/Contents
196 ?? Ss 0:00.42 /System/Library/CoreServices/pbs
202 ?? S 0:17.41 /System/Library/CoreServices/Dock.app/Contents/MacOS/
203 ?? S 0:31.82 /System/Library/CoreServices/SystemUIServer.app/Conte
204 ?? S 1:45.26 /System/Library/CoreServices/Finder.app/Contents/MacO
207 ?? S 0:00.18 /Applications/iTunes.app/Contents/Resources/iTunesHel
208 ?? S 10:27.46 /System/Library/PreferencePanes/UniversalAccessPref.p
209 ?? S 0:00.81 /Applications/iCal.app/Contents/Resources/iCalAlarmSc
210 ?? S 0:00.18 /System/Library/Frameworks/ApplicationServices.framew
211 ?? S 4:54.85 /Applications/Palm/Palm Desktop/Contents/Resources/Pa
212 ?? S 1:31.01 /Applications/Mail.app/Contents/MacOS/Mail -psn_0_157
216 ?? S 0:08.27 /Applications/Missing Sync for Palm OS/Missing Sync f
217 ?? S 0:16.04 /Applications/Missing Sync for Palm OS/Missing Sync f
218 ?? S 0:00.39 /Applications/StuffIt 11/MagicMenu.app/Contents/MacOS
219 ?? S 21:02.42 /Applications/Skype.app/Contents/MacOS/Skype -psn_0_2
226 ?? Ss 0:00.82 /Applications/StuffIt 11/MagicMenu.app/Contents/Resou
294 ?? S 0:00.32 /System/Library/Services/AppleSpell.service/Contents/
1234 ?? S 0:13.34 /Applications/Preview.app/Contents/MacOS/Preview -psn
One more question...does this shell stuff works on Window ?
Thank
Trevix
Inter application communication
Great !!! Thanks (As you can imagine I know nothing about Unix command...)
I'm working on the long debated problem of multiplatform application communication, using sockets to talk between Apps, trying to develop a "strong" protocol, where, for example, if App2 is closed, App1 is able to restart it and reconnect (and viceversa. I may post the stacks if someone is interested).
I'm having problems with timing the different calls of the protocol: I noticed that "opensockets" and "openstacks" do not work on Standalone applications (I may understand "openstacks", but why "opensockets" ?).
Do you think I can time the re-opening of the other app like this?
Is there a better way ?
Will it work on Window too ?
Thanks again
Trevix
I'm working on the long debated problem of multiplatform application communication, using sockets to talk between Apps, trying to develop a "strong" protocol, where, for example, if App2 is closed, App1 is able to restart it and reconnect (and viceversa. I may post the stacks if someone is interested).
I'm having problems with timing the different calls of the protocol: I noticed that "opensockets" and "openstacks" do not work on Standalone applications (I may understand "openstacks", but why "opensockets" ?).
Do you think I can time the re-opening of the other app like this?
Code: Select all
put the seconds into TheSeconds
repeat until IsOpen is true or the seconds > TheSeconds + 5
put shell("ps-wwx") into tProcessesOnMyMac
if offset ("/App2.app/",tProcessesOnMyMac) > 0 then
put true into IsOpen
exit repeat
end if
end repeat
Will it work on Window too ?
Thanks again
Trevix
I am running a chat server made with rev, and use standalones frequently. the opensockets property never ceased to work for me, so i'm a bit puzzled by your claim regarding that one. Can you please elaborate a bit more about what you try to do, and why the opensockets don't work for you?
Of course the same goes for the openstacks, this even more actually, as it's a core property of all that rev is about?
Of course the same goes for the openstacks, this even more actually, as it's a core property of all that rev is about?
Various teststacks and stuff:
http://bjoernke.com
Chat with other RunRev developers:
chat.freenode.net:6666 #livecode
http://bjoernke.com
Chat with other RunRev developers:
chat.freenode.net:6666 #livecode
Ok... you have stack App1 and stack App2.
They communicate fine using sockets. In the msgbox if you type "put the opensockets" or "put the openstacks", everything is fine and you get the list (for the "opensockets" you get the port of stack App2, since you locally did a "accept connections...", the socket open by stack App1 and the socket automatically opened for the answer back by App2....)
You save App2 as a standalone.
You open both in order to test them(App1 as a stack, App2 as a standalone).
They communicate fine...but if you look for opensockets, on App2 (the standalone) you see only the local port (opened by App2 with "accept connection..) and the socket opened by the App2 automatically (for the "answer back communication"). There is not the socket opened by stack App1 (that would be useful in order to know that it has connected). The "answerback" sockets could be someother program and you cannot be sure that it is from App1. I find this rather confusing...
As for the openstacks, on the msgbox of the stack there is not App2 (standalone).
If you do a "put the openstacks on fld..." on the App2, it return only App2 (not App1, even if you converted it in standalone)
The point is that you cannot use Opensockets and Openstack to safely check the connection on standalones.
But I knew this for "Openstacks" (this is why you have to check if a standalone is running doing a shell command...).
Sorry if I have been confusing...
They communicate fine using sockets. In the msgbox if you type "put the opensockets" or "put the openstacks", everything is fine and you get the list (for the "opensockets" you get the port of stack App2, since you locally did a "accept connections...", the socket open by stack App1 and the socket automatically opened for the answer back by App2....)
You save App2 as a standalone.
You open both in order to test them(App1 as a stack, App2 as a standalone).
They communicate fine...but if you look for opensockets, on App2 (the standalone) you see only the local port (opened by App2 with "accept connection..) and the socket opened by the App2 automatically (for the "answer back communication"). There is not the socket opened by stack App1 (that would be useful in order to know that it has connected). The "answerback" sockets could be someother program and you cannot be sure that it is from App1. I find this rather confusing...
As for the openstacks, on the msgbox of the stack there is not App2 (standalone).
If you do a "put the openstacks on fld..." on the App2, it return only App2 (not App1, even if you converted it in standalone)
The point is that you cannot use Opensockets and Openstack to safely check the connection on standalones.
But I knew this for "Openstacks" (this is why you have to check if a standalone is running doing a shell command...).
Sorry if I have been confusing...
Inter application communication
I've posted on Rev Online two stacks: Comm_App1 and Comm_App2.
I'm trying to do a solid standalone multiplatform communication, simulating the comm between a Calendar and its alarm application (locally).
Not so easy as it seems...
Any comments and updates are welcommed.
Trevix
I'm trying to do a solid standalone multiplatform communication, simulating the comm between a Calendar and its alarm application (locally).
Not so easy as it seems...
Any comments and updates are welcommed.
Trevix
Hi trevix
I tried to look at your code, but it was waaay too complex, and I was unable to find anything there due to that.
To show you a simple example, I have uploaded two working stacks myself, a server and a client. Please make an example that is not much more complex then mine, because only then People can tell you why it doesn't work, or what you can change to make it better.
Username:
BvG
Stacks:
Simplest Server Socket Example
Simplest Client Socket Example
I tried to look at your code, but it was waaay too complex, and I was unable to find anything there due to that.
To show you a simple example, I have uploaded two working stacks myself, a server and a client. Please make an example that is not much more complex then mine, because only then People can tell you why it doesn't work, or what you can change to make it better.
Username:
BvG
Stacks:
Simplest Server Socket Example
Simplest Client Socket Example
Various teststacks and stuff:
http://bjoernke.com
Chat with other RunRev developers:
chat.freenode.net:6666 #livecode
http://bjoernke.com
Chat with other RunRev developers:
chat.freenode.net:6666 #livecode
That the point...!
I started from one of the simple available server/client stack of RevOnline and I added the ability to always reconnect, even if one of the two app was off (that means to be able to restart the other App so it can reopen the socket).
And that is what I ended up with...!!!
The problem I cannot solve is:
I cannot restart (that means close and open) an app unless it has been launched with an openprocess. But people DO click on the application on the desktop...On OSX the problem is solved because the OpenProcess on an open app, does just that. On window instead it does not.
Aaaaah....It is so easy to do it in Applescritp. I guess I should just wait for Rev 2.9 that I believe will allow VBScripting, so I will be able to do it on OSX and Win (of course this leaves out Linux...).
Will look to your stacks. Thanks
I started from one of the simple available server/client stack of RevOnline and I added the ability to always reconnect, even if one of the two app was off (that means to be able to restart the other App so it can reopen the socket).
And that is what I ended up with...!!!
The problem I cannot solve is:
I cannot restart (that means close and open) an app unless it has been launched with an openprocess. But people DO click on the application on the desktop...On OSX the problem is solved because the OpenProcess on an open app, does just that. On window instead it does not.
Aaaaah....It is so easy to do it in Applescritp. I guess I should just wait for Rev 2.9 that I believe will allow VBScripting, so I will be able to do it on OSX and Win (of course this leaves out Linux...).
Will look to your stacks. Thanks