Code for minimizing application window in Mac? - macos

I'm wondering whether there is a way to write code for Mac OS 10.5 which will minimize and restore a window. What language would it be in? Could someone please give me an example or direct me to documentation on Apple's developer site I should look at?
Thanks!

Try this applescript:
tell application "Safari"
set miniaturized of window 1 to true
end tell

Apple | AppleScript
AppleScript is Apples native scripting language. The official link above includes very useful information on how you can get started.
I suspect that the following URL is what you may need. It provides information and sample code for scripting and automation in AppleScript:
AppleScript | Scripting and Automation

I had trouble with these working in 2023.
This worked for me to open chrome and then minimize.
tell application "Google Chrome"
activate
delay 1
end tell
tell application "System Events" to set visible of process "Google Chrome" to false

Related

How to shake the Google Chrome app with applescript?

I have one question.
I found app shake script with applescript.
(in this link: https://gist.github.com/gregferrell/7419080)
And I replace target app name "Terminal" -> "Google Chrome"
But It couldn't work.
I tested "Terminal" and "Finder", Good work!
How do I do?
Thanks.
Best wishes for you.

Open URL and Activate Google Chrome via Applescript

I have the following AppleScript that I wrote many years ago. I use this code to program buttons on my Harmony One universal remote to access online video services via Google Chrome. The code is not working. Google Chrome doesn't launch. I am running the code via RemoteBuddy. The code complies fine, but does not work.
Anyone have any thoughts on what might be the problem, or how I can improve the script to make it work?
tell application "System Events" to set open_applications to (name of everyprocess)
if (open_applications contains "Google Chrome") is true then
tell application "Google Chrome" to quit
else
tell application "Google Chrome"
activate
open location "http://xfinitytv.comcast.net"
end tell
delay 1
tell application "Google Chrome" to activate
end if
Try it this way:
tell application "Google Chrome"
if it is running then
quit
else
activate
open location "http://xfinitytv.comcast.net"
delay 1
activate
end if
end tell
Note: it's using the newer "Enhanced Application Model" (second line), more info here: How to check in AppleScript if an app is running, without launching it - via osascript utility
tell application "Google Chrome"
open location "http://WEBSITEHERE.com"
end tell
osascript -e 'tell application "Google Chrome" to open location "http://yourlink.com.html"'

Xcode 4.2 applescript - still broken?

I'd like to use AppleScript to automate some of my common build tasks. But it appears under Xcode 4.2, scripting is so badly broken as to be useless. I cannot even run a minimal script such as the following (with Xcode running and my project loaded):
tell application "Xcode"
build project of active project document
end tell
This gives me the error "missing value". The scripting dictionary supplied is opaque to say the least. Nothing I have found on the Developer site helps, and searching for answers elsewhere indicates I am not the only frustrated one. Does Apple not want us to use AppleScript with Xcode 4? I'm using 4.2 as I don't want to upgrade from Snow Leopard to Lion yet.
UPDATE: specific questions are 1) how do I perform simple AppleScripting with Xcode 4 and 2) where is this documented?
Here is what I use to build & run on an attached iPhone. Even if an application does not support scripting, you can always just use menu commands. It's not what you want for a production environment but this is just supposed to be a little helper app of yours, right?
(* compile and let it run on iPhone *)
enabledGUIScripting(true)
activate application "Xcode"
tell application "System Events"
tell process "Xcode"
click menu item "Run" of menu 1 of menu bar item "Product" of menu bar 1
end tell
end tell
on enabledGUIScripting(switch)
tell application "System Events"
activate -- brings System Events authentication dialog to front
set UI elements enabled to switch
return UI elements enabled
end tell
end enabledGUIScripting
To answer part 2, Xcode scripting is documented in its scripting dictionary. In AppleScript Editor, choose "Open Dictionary…" from the File menu and select Xcode.

AppleScript and non-scriptable applications

I'm wondering how can I script applications which has no dictionary. All information that I've found tells me nothing. But my experience says me that there is a way.
For example:
tell application "Firefox"
return count of windows
end tell
Will work. And it will work with "Opera" and other applications without dictionary at all. So the questions are:
1) Why does it work?
2) What else work in such a manner? Is there a list of all such actions?
Thank in advance!
You can to some extent script applications without an applescript dictionary by using 'tell application "System Events"'
tell application "Keynote" activate
tell application "System Events" to keystroke "c" using {command down}
end tell
end tell
This example activates Keynote and then copies the current selection. You can use similar code in many applications even if they don't have an applescript dictionary provided you also have the "Enable access for assistive devices" option checked in the "Universal Access" System Preference.
Edit:
This document gives some details of how Cocoa provides some support for Applscript in all applications:
http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/ScriptableCocoaApplications/SApps_about_apps/SAppsAboutApps.html
Under the heading Built-in Support for Standard and Text Suites
You can open the scripting dictionary of FireFox. Just open AppleScript Editor and go File → show dictionary, and choose FireFox from the list.
It just shows a very rudimentary dictionary. What happens is that the system library provides at least a basic set of commands (called the Standard Suite) to any Carbon or Cocoa app. This is what contains the definitions of window you used.
As Ian already wrote, in order to do more with such an app, you use the so-called UI scripting via System Events.
This nice website is a good place to start.

How can I open the Dropbox preferences window using Applescript?

How can I open the Dropbox preferences window using Applescript?
I'm assuming it would be something along the lines of
tell application "System Events"
tell application "Dropbox"
keystroke "," using command down
end tell
end tell
But this isn't working. Perhaps it's because Dropbox is running in the tray / background? ie: I can't switch to it using command-tab.
Thanks!
Unfortunately there is no way to do this. NSStatusItems (of which Dropbox is one) are not visible via accessibility. This weblog entry and this bug provide more information. Please file a bug and reference that bug number if this is important to you.

Resources