How to make Plex front most application after Media Centre startup...

I’m hoping someone can help me…

I wrote a Startup script for my Mac Mini Media Centre that runs at startup and mounts several network drives and runs a couple of processes which I built from various scripts from various threads here. The issue I have is that I can’t seem to get Plex (http://plexapp.com) to be the front most application once the script ends - the dock and finder always seem to be front most.

Can anyone point me in the right direction to solve this?


set NetworkShares to {"iTunes", "Share01", "Share02", "Share03"}
set ServerPath to "afp://my.lan/"
set UserName to "user"
set UserPassword to "password"
set mountedVolumes to list disks

repeat with ShareName in NetworkShares
	set SharePath to ServerPath & ShareName
	log ShareName
	
	if mountedVolumes does not contain ShareName then
		mount volume SharePath as user name UserName with password UserPassword
		log SharePath & " has been mounted as user " & UserName
	else
		log SharePath & " is already mounted"
	end if
	if ShareName contains "iTunes" then
		tell application "iTunesFS"
			activate
		end tell
	end if
end repeat

tell application "Plex"
	activate
end tell

tell application "System Events"
	tell process "Plex"
		set frontmost to true
	end tell
end tell

Thanks,

/ Hami

Model: Mac Mini
Browser: Safari 531.21.10
Operating System: Mac OS X (10.6)

I don’t know, but if I just tell an application to activate, it automatically becomes frontmost:

tell application appName to activate

ief2

EDIT: Or maybe you could wait until the Finder and the Dock are launched. Save this script as a stay open application:

on run
	set NetworkShares to {"iTunes", "Share01", "Share02", "Share03"}
	set ServerPath to "afp://my.lan/"
	set UserName to "user"
	set UserPassword to "password"
	set mountedVolumes to list disks
	
	repeat with ShareName in NetworkShares
		set SharePath to ServerPath & ShareName
		log ShareName
		
		if mountedVolumes does not contain ShareName then
			mount volume SharePath as user name UserName with password UserPassword
			log SharePath & " has been mounted as user " & UserName
		else
			log SharePath & " is already mounted"
		end if
		if ShareName contains "iTunes" then tell application "iTunesFS" to activate
		
	end repeat
	
	tell application "Plex" to activate
	
end run

on idle
	tell application "System Events" to if exists (some process whose name is "Finder") then if exists (some process whose name is "Dock") then
		tell process "Plex" to set frontmost to true
		
		quit me
	end if
	
	return 1
end idle

Without trying this myself, my thought would be to try hiding the Finder by setting its visible property to false instead of (or in addition to) activating Plex at the end of your script…

tell application "System Events"
	tell process "Finder"
		set visible to false
	end tell
end tell