Quantcast

Forums | MacLife

You are not logged in.

#1 2009-01-01 12:39 am

Funkey Monkey
Il Maestro spettacolare
From: On the podium.
Registered: 2003-01-27
Posts: 1467
Website

Quick AppleScript question -- should be easy for you pros.

I want an Applescript to do the following -- seems very simple to me, but I don't know how to do it.

I want it to do just three simple steps.

1.  open GraphicConverter  (I've mastered this, no problem.)
2.  type Command-D
3.  hit Enter


Why isn't this as simple as I imagine it to be?   Automator doesn't seem to help, either.

Can anybody crank out a quick script for me?

Offline

 

#2 2009-01-01 12:48 am

Fracai
Evacipate
From: St. Elsewhere
Registered: 2000-05-25
Posts: 2835

Re: Quick AppleScript question -- should be easy for you pros.

keystroke "d" using command down
keystroke return


   i am jack's amusing sig file
        http://alum.wpi.edu/~arno/i/s.png
Satellite Lot :: Second Summer

Offline

 

#3 2009-01-01 12:56 am

Funkey Monkey
Il Maestro spettacolare
From: On the podium.
Registered: 2003-01-27
Posts: 1467
Website

Re: Quick AppleScript question -- should be easy for you pros.

Yay!   It works!

Many thanks, Fracai.

I did this:

Code:

activate application "GraphicConverter"
tell application "GraphicConverter"
    tell application "System Events" to keystroke "d" using command down
    tell application "System Events" to keystroke return
end tell

Last edited by Funkey Monkey (2009-01-01 12:59 am)

Offline

 

#4 2009-01-01 11:31 am

Funkey Monkey
Il Maestro spettacolare
From: On the podium.
Registered: 2003-01-27
Posts: 1467
Website

Re: Quick AppleScript question -- should be easy for you pros.

OK -- I have a new problem.

When I bootup, the cursor is by default in the top left corner.   This means that when GraphicConverter starts the slideshow, it keeps the menu bar and the dock visible.    How can I modify this AppleScript to move the cursor to the middle of the screen before starting the slideshow?

Offline

 

#5 2009-01-01 2:26 pm

Macskeeball
Member
Registered: 2002-02-07
Posts: 8014
Website

Re: Quick AppleScript question -- should be easy for you pros.

Here's a slight simplification

Code:

activate application "GraphicConverter"
tell application "System Events"
    keystroke "d" using command down
    keystroke return
end tell

If that doesn't work, this should.

Code:

tell application "GraphicConverter"
    activate
    tell application "System Events"
        keystroke "d" using command down
        keystroke return
    end tell
end tell

Last edited by Macskeeball (2009-01-01 2:29 pm)


tech writer for hire

Offline

 

#6 2009-01-01 3:48 pm

Funkey Monkey
Il Maestro spettacolare
From: On the podium.
Registered: 2003-01-27
Posts: 1467
Website

Re: Quick AppleScript question -- should be easy for you pros.

Thanks Skee, but that codechange doesn't change the issue with my mouse pointer location.

When I bootup and the script runs automatically, the mouse pointer is in the top left of the screen.   This causes GraphicConverter to show the menubar during the slideshow.

I need to know how to move the mouse pointer with AppleScript.

Offline

 

#7 2009-01-01 4:19 pm

Miles
Now I fight for wisdom!
Administrator
From: Michigan
Registered: 2001-07-21
Posts: 4506
Website

Re: Quick AppleScript question -- should be easy for you pros.

I don't think it can be done with AppleScript alone.  There are Carbon calls to do it, so you can either use a third-party scripting addition, or something like the following:

Code:

do shell script "python -c 'from Quartz import *; CGEventPost(kCGHIDEventTap, CGEventCreateMouseEvent(None, kCGEventMouseMoved, CGPointMake(200,200), kCGMouseButtonLeft))'"

Offline

 

#8 2009-01-01 5:03 pm

Funkey Monkey
Il Maestro spettacolare
From: On the podium.
Registered: 2003-01-27
Posts: 1467
Website

Re: Quick AppleScript question -- should be easy for you pros.

Miles wrote:

I don't think it can be done with AppleScript alone.  There are Carbon calls to do it, so you can either use a third-party scripting addition, or something like the following:

Code:

do shell script "python -c 'from Quartz import *; CGEventPost(kCGHIDEventTap, CGEventCreateMouseEvent(None, kCGEventMouseMoved, CGPointMake(200,200), kCGMouseButtonLeft))'"

Hey Miles, that worked great on my brand new iMac, but it says

ImportError: no module named Quartz

on my old iBook.   

Is it because my iBook is running Tiger, or is it because it's a G3, which can't run Quartz?  (IIRC.)

Offline

 

#9 2009-01-01 5:43 pm

Macskeeball
Member
Registered: 2002-02-07
Posts: 8014
Website

Re: Quick AppleScript question -- should be easy for you pros.

You're thinking of Quartz Extreme, which boosts performance by using the GPU and was introduced with 10.2 Jaguar. Quartz Extreme couldn't run on machines without PCI-based GPUs (at least not without a 3rd party hack). Quartz is part of every OS X version.

As for the code change, it wasn't intended to address the mouse issue at all, just make the code a little more cleanly written. I figured someone else would handle that; we're just building on each other's work here.

Last edited by Macskeeball (2009-01-01 5:49 pm)


tech writer for hire

Offline

 

#10 2009-01-03 8:09 am

Funkey Monkey
Il Maestro spettacolare
From: On the podium.
Registered: 2003-01-27
Posts: 1467
Website

Re: Quick AppleScript question -- should be easy for you pros.

Funkey Monkey wrote:

ImportError: no module named Quartz

on my old iBook.

MacSkeeball wrote:

You're thinking of Quartz Extreme, which boosts performance by using the GPU and was introduced with 10.2 Jaguar. Quartz Extreme couldn't run on machines without PCI-based GPUs (at least not without a 3rd party hack). Quartz is part of every OS X version.

So, any ideas why this script doesn't work on my iFrame, running 10.4.11, but it does work on my iMac, running 10.5.6?

Offline

 

#11 2009-01-03 5:08 pm

Miles
Now I fight for wisdom!
Administrator
From: Michigan
Registered: 2001-07-21
Posts: 4506
Website

Re: Quick AppleScript question -- should be easy for you pros.

The Python/Objective-C bindings that it uses are only included with 10.5.  You could download, compile, and install them yourself, but at that point you're maybe better off just compiling a simple program to do what you want.

Code:

#include <ApplicationServices/ApplicationServices.h>
#include <stdlib.h>
#include <stdio.h>

int main(int argc, char *argv[])
{
    if (argc == 3) {
        char *arg1end, *arg2end;
        float x = strtof(argv[1], &arg1end);
        float y = strtof(argv[2], &arg2end);
        if (!((x == 0.0 && argv[1] == arg1end) || (y == 0.0 && argv[2] == arg2end))) {
            CGEventRef ev = CGEventCreateMouseEvent(NULL, kCGEventMouseMoved, CGPointMake(x, y), kCGMouseButtonLeft);
            CGEventPost(kCGHIDEventTap, ev);
            CFRelease(ev);
            return 0;
        }
    }
    printf("usage: %s x y\n", argv[0]);
    return 1;
}

Offline

 

#12 2009-01-04 8:43 am

Funkey Monkey
Il Maestro spettacolare
From: On the podium.
Registered: 2003-01-27
Posts: 1467
Website

Re: Quick AppleScript question -- should be easy for you pros.

Miles wrote:

but at that point you're maybe better off just compiling a simple program to do what you want.

Code:

#include <ApplicationServices/ApplicationServices.h>
<snip>
}

Miles -- could you walk me through this just a little bit?   Is it simple as copy/pasting somewhere into XCode and hitting "Compile?"

I have zero experience with compiling anything on my mac....

Or would somebody mind compiling this as a Universal app for me?   big_smile

Last edited by Funkey Monkey (2009-01-04 8:51 am)

Offline

 

#13 2009-01-04 9:13 am

Funkey Monkey
Il Maestro spettacolare
From: On the podium.
Registered: 2003-01-27
Posts: 1467
Website

Re: Quick AppleScript question -- should be easy for you pros.

Wait a sec... does that program check to see if the mouse is at {0,0} first?   Because when the iFrameā„¢ boots up, it doesn't start at 0,0.   It's more like 5,5.... somewhere just about the lower part of the apple in the apple menu.

Can we just skip the "if" and have it click (or just move) to about {200,200} no matter what?

Offline

 

#14 2009-01-04 2:40 pm

Funkey Monkey
Il Maestro spettacolare
From: On the podium.
Registered: 2003-01-27
Posts: 1467
Website

Re: Quick AppleScript question -- should be easy for you pros.

Funkey Monkey wrote:

OK -- I have a new problem.
When I bootup, the cursor is by default in the top left corner.   This means that when GraphicConverter starts the slideshow, it keeps the menu bar and the dock visible.

Well, I fixed the problem by correctly diagnosing the cause.  hmm
It turns out that the dock and menu bar came up during the GraphicConverter slideshow because other applications were loading in the background.  (Specifically, Folding at Home, Growl Notifier, and DropBox)   When those apps booted, it confused GC.   
So I had the script wait a full 90 seconds before opening GraphicConverter.  Now everything can get set up before starting the slideshow.
The code is short and clean.   This really was as simple as I thought it should be... it just took three days to figure out the simple solution.   confused

Code:

tell me to delay 90
activate application "GraphicConverter"
tell me to delay 15
tell application "System Events"
    keystroke "d" using command down
    keystroke return
end tell

Problem solved!

Special thank you to all you guys who helped with the scripting/programming suggestions! up

Last edited by Funkey Monkey (2009-01-04 2:53 pm)

Offline

 

#15 2009-01-04 6:21 pm

Macskeeball
Member
Registered: 2002-02-07
Posts: 8014
Website

Re: Quick AppleScript question -- should be easy for you pros.

Do you really need the "tell me to," considering those aren't inside a tell block? I don't think those are necessary, so the following should work.

Code:

delay 90
activate application "GraphicConverter"
delay 15
tell application "System Events"
    keystroke "d" using command down
    keystroke return
end tell

tech writer for hire

Offline

 

Board footer

Powered by PunBB 1.2.6
© Copyright 2002–2005 Rickard Andersson