I want my application to be able to show/hide iTunes’ window when the user moves the mouse in a certain region of the screen. On Windows, I managed to do this using the Win32 functions:
FindWindow() // used to find the iTunes window
MoveWindow() // to set the position of the iTunes window
ShowWindow() // to hide/show the iTunes window
So, not to hard on Windows.
But how does this work on OS X? Is is even possible?
tell application “iTunes” to get the bounds of window 1
And if performance isn’t really an issue you can compile the script on the fly…
NSString *scriptString=@"tell application \"Finder\"\r to get the bounds of window 1"; // This can't be more than 1012 characters
NSAppleScript *iTunesScript=[[NSAppleScript alloc]initWithSource:scriptString];
NSDictionary *errorInfo;
[iTunesScript executeAndReturnError:&errorInfo];
[iTunesScript release];
Is it possible to “precompile” the scripts once for speedup and then just run them? Does the compilation occur in the executeAndReturnError method? Sorry for such stupid questions, but I don’t know anything about Cocoa nor Obj-C.
[quote]you can save the save the script you provided as a compiled
.scpt made in Script Editor, and include it in the bundle of your
application. You can initialize an NSAppleScript object with the URL file
path of the script - rather than the uncompiled source code - and just run
it. Use initWithContentsOfURL:error and executeAndReturnError: . You can do
so with an already-compiled script and it won’t re-compile.[/quote]
Cool, thanks. Anyway, seems like the compilation time ain’t that important either (it’s actually something else that took a bit more time), so I’ll stick to the code-only version. Cheers!