Applescript Issues

If you have some question about Spark, you can post here.

Applescript Issues

Messagepar gordon142 » Mer 19 Mar 2008 06h15

I am trying to use a simple applescript with Spark to activate my browser and select the address field. The script is as follows:

tell application "System Events" to set FoxRunning to (name of processes) contains "firefox-bin"
if FoxRunning is true then

tell application "Firefox" to activate
tell application "System Events" to keystroke "l" using command down
else
tell application "Firefox" to launch
tell application "Firefox" to activate
end if

For some reason, only when using Spark, this script does not work right. Specifically, the line where I call system events to do the keystroke does not interact well with spark. It works absolutely fine from the script editor, but when I try to invoke it using Spark, it only works the first time. After that, I get the following symptons: It takes two presses of the keystroke to get it to go through, and it only activates FireFox, and does not select the address field. I have to restart the Spark Daemon to get it to work properly, and then again, it will work only once. As far as I can tell, this is specific to spark, and not an applescript issue. Anyone have any ideas?
gordon142
Nouveau
 
Messages: 2
Inscrit le: Mer 19 Mar 2008 06h08

Re: Applescript Issues

Messagepar Grayfox » Mer 19 Mar 2008 10h15

Hello,

Your diagnostic is right. This is a problem with the keystroke event. But this is not really a Spark issue, but a System issue.

The normal event flow for each Spark HotKey is like this:
- HotKey down (send by the OS).
- Execute action.
- HotKey Up (send by the OS).

Now, with your script it is like this:
- HotKey down (send by the OS).
- Execute action (your apple script).
-------- and that's all.

Then the next time you press your hotkey
- HotKey Up (send by the OS).

If you release your HotKey during the script execution, the OS will lost the key up event and it will think the key is always down.

Until I find a way to workaround this problem, there is a simple solution to avoid it. Release your Keystroke only when the script is over, so the OS will not lost the HotKey Up event.
«Des tas de gens seraient aussi lâche que moi s'ils en avaient le courage.» Rincevent
Avatar de l’utilisateur
Grayfox
Tyran Spammer
 
Messages: 5400
Inscrit le: Mer 04 Fév 2004 10h45
Localisation: Dans une dimension parallèle

Re: Applescript Issues

Messagepar gordon142 » Mar 01 Avr 2008 18h35

OK, so I tried the following script, but it doesn't work any better.

tell application "Firefox" to activate
tell application "System Events"
key down command
keystroke "l"
key up command
end tell

Or am I not completely understanding you?
gordon142
Nouveau
 
Messages: 2
Inscrit le: Mer 19 Mar 2008 06h08

Re: Applescript Issues

Messagepar Grayfox » Mer 02 Avr 2008 10h09

In fact, the event flow is like this.
For example, you choose the F7 key for trigger this action.

- F7 down => Start your AppleScript
- The script disable the keyboard (side effet when using key down and keystroke commands)
- The script simulate cmd + L
- The script reenable the keyboard.

If the "F7 up" event occurs when the keyboard is disabled, the system will not catch it, and it will think your key is always down.
So the next time you will press F7, the system will ignore the key down event and it will not trigger your script.

I'm planning to add an option to trigger the script when the "key up" event occured (instead of the "key down") to prevent this problem.

As I suggest in my previous post, if you keep the key down long enough, this problem will not occured.
«Des tas de gens seraient aussi lâche que moi s'ils en avaient le courage.» Rincevent
Avatar de l’utilisateur
Grayfox
Tyran Spammer
 
Messages: 5400
Inscrit le: Mer 04 Fév 2004 10h45
Localisation: Dans une dimension parallèle

Re: Applescript Issues

Messagepar Invité » Mer 22 Avr 2009 01h57

I think it's this bug that's stopping me from getting proper keyboard shortcuts for opening various sessions with Terminal.app. Unfortunately, Terminal is pretty dumb, and can't be scripted to "open a new tab with ssh" in any other way than:

tell application "Terminal" to activate
tell application "System Events" to tell process "Terminal" to keystroke "t" using command down
tell application "Terminal" to do script "exec ssh blah.bla" in first window

While it works fine when launched from Spark config window, script editor or command line (with osascript), it fails while I try to use the shortcut that has this script assigned.
At the moment I've ended up using Spark's "Text/Keyboard action" to simulate press of option-t,e,x,e,c.... Problem with that approach is that I need to have delay set to at least 6ms, or it will start loosing characters. And the approach is quite ugly :(

Help?
Invité
 

Re: Applescript Issues

Messagepar Grayfox » Mer 22 Avr 2009 15h18

I think this is an issue with System Event keystroke simulation that conflit with you current keyboard state.

Example:
You assign your script to 'opt + @'. When you invoke it, the opt key is down. Your script launch the terminal. push the cmd key down, send the t keystroke event, and then release the cmd key. The terminal App will receive a 'cmd + opt + T' event.

If you set this action to a shortcut without any modifier, or with cmd as only modifier, it should works.
«Des tas de gens seraient aussi lâche que moi s'ils en avaient le courage.» Rincevent
Avatar de l’utilisateur
Grayfox
Tyran Spammer
 
Messages: 5400
Inscrit le: Mer 04 Fév 2004 10h45
Localisation: Dans une dimension parallèle

Re: Applescript Issues

Messagepar Invité » Mer 22 Avr 2009 22h54

Yeah, that might have been an issue here... I was using ctrl-cmd-n as a keybind. I've switched to another method of opening tab though:

tell application "Terminal" to activate
tell application "System Events"
click menu item ¬
"default" in menu "New Tab" of menu item ¬
"New Tab" in menu "Shell" of menu bar item ¬
"Shell" in menu bar 1 of process "Terminal"
end tell
tell application "Terminal" to do script "clear; exec ssh trala.la" in first window

Hopefuly this will be useful to someone else... :)
Invité
 

Voir les options[Cacher] Réponse rapide


Entrez le code exactement comme il apparaît. Il n’est pas sensible à la casse et il ne peut pas y avoir de zéro.
 

Retourner vers Spark

Qui est en ligne ?

Utilisateurs parcourant actuellement ce forum : Aucun utilisateur inscrit et 1 invité

cron