Hello, I’m a very new Applescripter but I’m finding it a lot of fun. Such a cool tool and such cool people who are into it.
So, I’ve run into a problem with one of my scripts that I’m sure has a very simple solution, but I’ve been scratching my head over it for hours and it’s finally time to ask for some help.
Here’s the deal: I have written a script that will let me send out a Tweet to Twitter using Launchbar (http://www.obdev.at/products/launchbar/index.html) and a “do shell script”. It works just like I want it to. (I even got it to work with Growl which makes this baby coder very proud!) But, of course, Twitter goes down all the time, so I got the bright idea of using a separate Stay Open Script Application to try to resend the Tweet every 5 minutes (for up to 2 hours) in the event that the first script encounters an error. Reading around on Google, it seemed like the smart way to do that would be to use On Idle in the Script Application – that way it wouldn’t use up much CPU power during the loops when it was called for and could be easily quit at any time.
But try as I might – and I tried and tried and tried – I couldn’t figure out how to pass the variables from the first script over to the Script Application so they could be used within an On Idle/End Idle routine. No matter what I did, when the Script Application ran, I kept getting the error “Variable Not Defined”.
The only way I was able to make it work was by making the Script Application a subroutine of the initial script and passing along the variables in parentheses, like this:
tell application "Keep Trying Twitter" to TryAgain(Tweet, s)
Those variables passed along fine and I was then able to use “do shell script sleep” within TryAgain to create the necessary delay between loops while still keeping CPU consumption down. The problem is that when the Stay Open App is “sleeping”, it won’t quit from the Dock (I have to Force Quit it) and when the Stay Open App first runs, it gives me a spinning beach ball for 2 minutes in Launchbar for some reason. I just think that On Idle is the better way to go than the subroutine I used, but I just can’t make it work.
Can anyone help me? It feels like there is some simple inheritance thing that I’m missing…
It’s tempting to post my actual scripts, but I think it’ll be easier if I just post up some sample bits of code that show what I’m trying to do – I don’t want to scare anyone off by asking you to help rewrite my actual scripts (although I’m happy to post them if people want to see them!)
So keeping it very simple, if I use this script to get the text from LaunchBar
using terms from application "LaunchBar"
on handle_string(s)
run application "Banana"
end handle_string
end using terms from
How can I get this Stay Open Script Application – “Banana” – to be able to use what’s in that s variable?
on idle
display dialog s
return 10
end idle
Any help would be greatly appreciated! Thank you very much!
Alex