Need Applescript to repeat every x number of seconds - osx-lion

Here is my script so far:
property timeDelay : 5
on appOpen(appName)
tell application "System Events" to set appNameIsRunning to exists (processes where name is appName)
return appNameIsRunning
end appOpen
if appOpen("iChat") then
tell application "iChat"
repeat with theService in services
if connection status of theService = disconnected or connection status of theService = disconnecting then
log in of service (name of theService)
end if
end repeat
end tell
end if
Basically, it checks a single time if any of your iChat/Messages accts are logged out. If they are, log them in. It works.
However, I would like this to be a 'Stay Open' app. In the past I've used the pattern
on idle
-- do stuff
end idle
..but for some reason it's erroring when I try to compile.
Any idea why this would be happening?
EDIT:
Ok -- still not sure why this was occurring, but I was able to fix the problem by simply making a new script. I have no idea why this error was coming up but it looks like it's good now. Thanks for the help guys.

This doesn't make sense...
tell application "System Events" to set appNameIsRunning to exists (processes where name is appName)
You want this...
tell application "System Events" to set appNameIsRunning to exists process appName
The reason is that "processes where name is appName" will return a list (whether it has one item or many it's still a list) and it makes no sense to check "exists" of a list.
I'm not sure about the error but I hope that solves your problem.

This works for me on 10.6.8
property timeDelay : 5
on appOpen(appName)
tell application "System Events" to set appNameIsRunning to exists process appName
return appNameIsRunning
end appOpen
on idle
if appOpen("iChat") then
tell application "iChat"
repeat with theService in services
if connection status of theService = disconnected or connection status of theService = disconnecting then
tell service (name of theService) to log in
end if
end repeat
end tell
end if
return timeDelay
end idle

Related

Different Script (SAP GUI) Codes for the same process in two different computers

I want to automate some operations for my works so I record a Script on SAP GUI(SAP LOGON PAD 720), then use it to create a excel macro and it works perfectly on my computer, but when I try to run it in other computers, it doesn't work at all and when I record the same process in other PC's the Script's code is different than that one which appeared in my PC. I want to know how this can be possible, how can I change the "code form" or "code language" on my PC so when I record a script it can be used on every computer.
This is the Script from my PC
If Not IsObject(application) Then
Set SapGuiAuto = GetObject("SAPGUI")
Set application = SapGuiAuto.GetScriptingEngine
End If
If Not IsObject(connection) Then
Set connection = application.Children(0)
End If
If Not IsObject(session) Then
Set session = connection.Children(0)
End If
If IsObject(WScript) Then
WScript.ConnectObject session, "on"
WScript.ConnectObject application, "on"
End If
session.findById("wnd[0]").maximize
session.findById("wnd[0]/tbar[0]/okcd").text = "vl03n"
session.findById("wnd[0]").sendVKey 0
'This is the script I recorded from my computer,in other pc this "LIKP-VBELN" doesnt appear
session.findById("wnd[0]/usr/ctxtLIKP-VBELN").text = "8105148724"
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[0]/tbar[1]/btn[7]").press
And this is if I record the same process from others PC's
If Not IsObject(application) Then
Set SapGuiAuto = GetObject("SAPGUI")
Set application = SapGuiAuto.GetScriptingEngine
End If
If Not IsObject(connection) Then
Set connection = application.Children(0)
End If
If Not IsObject(session) Then
Set session = connection.Children(0)
End If
If IsObject(WScript) Then
WScript.ConnectObject session, "on"
WScript.ConnectObject application, "on"
End If
session.findById("wnd[0]").maximize
session.findById("wnd[0]/tbar[0]/okcd").text = "vl03n"
session.findById("wnd[0]").sendVKey 0
'here is when the error begin "LIKP-VBELN" doesnt appear anymore so that is why the macro doesnt work
session.findById("wnd[0]/usr/ctxt").text = "8105148724"
session.findById("wnd[0]/usr/ctxt").caretPosition = 10
session.findById("wnd[0]").sendVKey 0
session.findById("wnd[0]/tbar[1]/btn[7]").press
Check the LAN connection for the client and ensure its set to High Speed.
Regards,
ScriptMan

How to notify from god only on process crash?

I'd like to get a notification from god when a process stops as a result of an error, but not otherwise. I'm looking for behavior like this example from doc/god.asciidoc:
w.transition(:up, :start) do |on|
on.condition(:process_exits) do |c|
c.notify = 'tom'
end
end
... except that only triggers if the process exits with a nonzero status. Do I need to write a custom :process_exits_with_error condition? If so, how would I find the exit status?

Quickfix/J - Automatic re logon after Session disconnect("Done", false);

I have a Quickfix/J implementation and when I call this:
// from the sender/initiator
Session.lookupSession(sessionId).disconnect("Done", false);
I get the expected behaviour on the onLogout handlers
SenderFixEngine standalone logged off
Receiver Fix Engine logged OFF, next sender num : 2 next target num : 3
but I then immediately get the reverse happening automatically
Receiver Fix Engine logged ON next sender num : 3 next target num : 4
SenderFixEngine standalone logged on
The usual QF app design is not run-and-done, but an app that stays on during the duration of a session. Thus, if the session is broke for some reason, the engine immediately tries to reconnect so you don't miss anything.
If you really want to stop, you should call Initiator.stop(). Or better yet, just have your app terminate itself.
I honestly don't see any good reason to call disconnect().

(AHK) Confirm before loading a program.

Curious as to how to make a popup asking to confirm if I want to load the program before it loads. Example:
^g::Run C:\GW2\gw2.exe
Although it does not seem that you have done a lot of homework, I'll provide a solution here.
^g::
MsgBox, 4100, , Would you like to launch GW2?, 5 ; 5-second timeout.
IfMsgBox, No
Return ; User pressed the "No" button.
IfMsgBox, Timeout
Return ; Timed out.
run, C:\GW2\gw2.exe
Return

Stop httputils service in basic4android

I am using basic4android and I made an application that uses httputils services. Sometimes a remote error occurs (possible server overload or limited internet connection) and the application exits with the error message box. The activity closes but httputils service is still running. While I reopen the activity new error occurs, because of the unfinished job of httputils. Everything is OK only if I choose to stop the activity in the second error.
Is there any way to determine if the httputils service is running by a previous instance of my app? Or better, a way to try to stop this service either its running or not.
HttpUtils errors should not cause your program to exit. You should check IsSuccess to make sure that the call succeeded or not.
You can stop the service from running by calling StopService(HttpUtilsService).
Public Sub StationTransfer_Click
Dim job As HttpJob
job.Initialize("MyJob", Me)
Dim URL As String="https://www.yourserver.com/myjob.asmx/GetData?parameter1=abc"
job.Download(URL)
ProgressDialogShow2("Getting data From Server...", True)
End Sub
Sub JobDone(Job As HttpJob)
Select Job.JobName
Case "MyJob"
HandleMyJob(Job)
End Select
Job.Release
End Sub
Sub HandleMyJob(Job As HttpJob)
If Job.Success = False Then
ToastMessageShow("Error downloading Data", True)
ProgressDialogHide
Return
End If
....
end Sub
if there is an httpjob error you catch it in the handler function by looking at the status. if the status is not success than you catch it and display a message.