Any way to tell if an application is hidden or not?

Hello.

I would like to know how I would go about telling if an application is hidden or not. In this case, iTunes.

Basically, I want a script that toggles an app between hidden and shown, i.e. not hidden as in visible.

Is it possible to tell if iTunes is hidden? And how would I go about making a script that would “If iTunes is hidden, show it. Else hide iTunes”? Etc…

I had found a page on Google that I thought would help, but was no help at all but implies that it is possible. I just can’t decipher it.
http://www.sonsothunder.com/devres/metacard/tips/proc004.htm

This is a quick test with Safari:

tell application "System Events"
	set visible of process "Safari" to not visible of process "Safari"
end tell

It seemed to work until AppleScript freaked out. Let me play around with this…

…Success. iTunes works. I can toggle iTunes shown and hidden with a mouse press. Thanks! :smiley:

Good idea! I think I’ll use a script like this, too. I am always switching to iTunes just to see what song is playing…

actually…


set trackInfo to "unknown"
tell application "iTunes"
	if (class of current track is URL track) then
		set trackInfo to current stream title
	else
		set trackInfo to (artist of current track as string) & " - " & (name of current track as string)
	end if
end tell

display dialog trackInfo buttons {"OK"} default button "OK"

Works with radio tracks, too!

I’m using the script I asked for in a DragThing Dock of all things.

The iTunes icon is the script I asked for. Clicking it hides or shows iTunes. It’s very convenient. The other docks control simple scripts “Previous Track”, “Playpause” and “Next Track” of course.

@Redsweater, that script may come in handy when I add a “dock” for the title of the song.

The way I see it, why run a bloated Konfabulator when a DragThing Dock can do the same thing with less overhead? Sure, it ain’t as fancy, but it is functional and it looks as good as you want it to look.

Cool - I didn’t know that DragThing allowed such customization to the docks.

DragThing will run AppleScripts from within the app if you save them as the default AppleScript document type. So basically, you can make script after script perform tedious actions and have them all in docks. I also made a “Cleanup the Desktop” script yesterday. Then you just assign a keypress to the script and viola! You are fully automated. I <3 AppleScript.

I just installed it and tried it out. It’s pretty good. It’s still not good enough for me to close up shop on FastScrips, since it’s really slow at running the Script, and doesn’t do any elegant integration with the front-most app like FS does.

I have been surprised that more hotkey enabled apps don’t make their AppleScript execution experience better. I keep waiting for one of them to give FS a real run for the money, but they always lack something important. (to me, anyway! :slight_smile: )

Nice !
Now download QuickSilver from versiontracker (free).
Change the last line of code to:

tell application "Quicksilver" to show large type trackInfo

And you get beautifull bezel large type !

(With QS you can also make mouse triggers, keyboard triggers and open apps / docs/ urls with keyboard abbreviations; combines very well with Applescript)

Very nice! A few rough edges, but I really like the fancy text display. Script launching is faster than most apps, too.

No, no, no. :wink:

Interesting:
with Dragthing you can make a dock that only shows up when a specific app is active.

Therefore:
make a Safari dock that contains all Safari related Applescripts
make a Excel dock that contains all Excel related AS’s etc.

Looks better than the Applescript menu…

Why?
At least using FastScripts, I see the same behaviour. When I’m working in Safari, I can see and execute Safari specific scripts (plus my user-defined “universal” or system-wide scripts). And also the super-cool feature of invoking them using keystrokes, being executed almost immediately, using “path to me” in a real fashion, etc. :rolleyes:

Thanks, jj :slight_smile:

One thing I am thinking about adding to FastScripts is some kind of “tear-off menu” idea so you could turn the menu or any submenu into a floating window. I can see some use for having easy mouse access to a bunch of scripts from a given category.

I didn’t mean to start an argument. Please don’t.

I use DT because I can get creative and make a nice interface for them. I do not want to have to dig through menus! If I liked menus, why would I need DragThing? I could just have one big menu… like the Windows Start Menu. But I’d rather have it all at my fingertips. Also, I already purchased the uberuseful DragThing, I don’t want to have to buy another app when DT can do the same thing.

I don’t mind the delay. I notice no delay in the iTunes Dock though. It’s only one line of code (Aside from the “Tell Application “Safari”” part.) so it’s fast acting.

Besides, my buttons look oh so cool when they have the shadow on.

Okay, now. I need to extend my script. How can I tell if iTunes is the frontmost app? The script works great until another app becomes frontmost, then it only hides and shows behind the other apps. So I need to be able to tell if it’s at the front and if not, then bring it front.

Then, just bring iTunes allways to the front (if it isn’t the frontmost, it will become the frontmost; if it is the frontmost, it will remain the frontmost):

activate application "iTunes"

I tried that, but something was going wrong. It kept freaking out. iTunes would hide, THEN come forward and show again. Even though the “Bring Forward” part was before the Hide part.

I fixed it with some If…Then…Else stuff. Works perfect now.

tell application "System Events"
	if exists process "iTunes" then
		if visible of process "iTunes" is not true then
			set visible of process "iTunes" to true
			set the frontmost of application process "iTunes" to true
		else
			set visible of process "iTunes" to false
		end if
	else
		tell application "iTunes" to activate
	end if
end tell

Basically, it also launches iTunes if it’s not running already whereas before it would cause errors.