Appliction status abfrage möglich ?

H

Hendril

Aktives Mitglied
Thread Starter
Dabei seit
13.03.2005
Beiträge
216
Reaktionspunkte
2
Ja ich hab gestern ein schönes Appelskript hier im Forum gesehen und meinen Bedingungen angepasst.

Aber ich bin mit 1-2 Sachen nicht ganz zufrieden. Ich poste mal herrein was ich bisher so geschrieben hab.

set theDate to current date
set theTime to time of the theDate
set theDay to weekday of theDate
set d to current date
set derTag to text -2 thru -1 of ("0" & d's day)
set Monat to word 3 of ((current date) as text)
set MonatsListe to {January, February, March, April, May, June, July, August, September, October, November, December}

repeat with i from 1 to 12

if d's month = item i of MonatsListe then
set MM to text -2 thru -1 of ("0" & i)
exit repeat
end if
end repeat


set Jahr to ((year of d) as text)
set dasDatum to theDay & derTag & "." & Monat

-- Datumskonvertierung für say
(* tell application "Finder"
set sound to 0
end tell *)

set probeItunes to false
set probeItunesrun to false
tell application "System Events"
if process "iTunes" exists then set probeItunesrun to true
end tell

if probeItunesrun = true then
set probeItunes to true
tell application "iTunes"
set probeItunesplay to player state as text
if player state = paused then
set probeItunes to false
end if
if player state = stopped then
set probeItunes to false
end if
end tell
end if

(* Es soll mir mal jemand erklären warum ich einen Händler setzen muß obwohl ich ihn nicht garnicht benutze *)

(* Um die Begrüßung abzuschalten bitte in der nächsten Zeile die "--" entfernen. Achtung !! Dies muß nochmaleinmal an einer anderen Stelle des Skriptes getan werden *)
-- (*

if probeItunes = true then
tell application "iTunes"
set sound volume to 15
end tell
end if

-- Überprüfung ob Itunes läuft, ggf. Lautstärke anpassen

delay 2

if theTime < 21600 then
say "UP late, o Master i will serve you! Master it's " & dasDatum & "."
else if theTime < 43200 then
say "Good morning, o Master i will serve you! Master it's " & dasDatum & "."
else if theTime < 64800 then
say "Good Afternoon, o Master i will serve you! Master it's " & dasDatum & "."
else
say "Good evening, o Master i will serve you! Master it's " & dasDatum & "."
end if

-- Zur Abschalten der Begrüßung bitte die "--" entfernen
-- *(


if probeItunes = true then
tell application "iTunes"
set sound volume to 100
delay 15
set theTrack to current track
set theTrackName to name of theTrack
set theTrackArtist to artist of theTrack
end tell

tell application "iTunes"
set sound volume to 15
say "This is " & theTrackName & ", by " & ¬
theTrackArtist & ". "
set sound volume to 100
end tell
end if

-- sollte Itunes schon laufen wird nun der Titel angesagt

if probeItunes = false then
delay 15
say "I will put some music on"

tell application "iTunes"
activate
set sound volume to 100
set theTrack to some file track of user playlist "Meine Top 25"
-- Anstelle von "Meine Top 25" einfach eure Lieblingplalist eintragen
set theTrackName to name of theTrack
set theTrackArtist to artist of theTrack
play theTrack
set collapsed of window 1 to true
end tell

tell application "iTunes"
activate
set sound volume to 15
say "This is " & theTrackName & ", by " & ¬
theTrackArtist & ". "
set sound volume to 100
end tell
end if

-- Itunes starten, zufällig wird ein Track aus "Meine Top 25" abgespielt

delay 10

property theURL : "http://www.icewars.de/index.php?action=login&name=XXXXXXXXXX&pswd=XXXXXXXXXXX&submit=1"
-- Anstelle der XXX eure Zugangsdaten eintragen
open location theURL
delay 30

-- Ja hier könnte auch http://www.spiegel.de stehen.

tell application "Mail"
activate
check for new mail

delay 60
set unreadCount to unread count of inbox
tell application "iTunes"
set sound volume to 15
delay 1
if unreadCount is equal to 0 then say ¬
"You have no new messages!"
if unreadCount is equal to 1 then say ¬
"You have a new message!"
if unreadCount is greater than 1 then say ¬
"You have " & unreadCount & " new messages!"
delay 1
set sound volume to 100
end tell
end tell
-- Mail unread count mit Ansage.

erstmal danke an Bqit.

So meine "Problem" sind:

Kann ich z.B.:
- Eine Syntax einfügen das überprüft ob eine Website schon geöffnet ist ?
-/edit leider doch nicht /edit Wie kann ich überprüfen ob eine Anwendung schon gestartet worden ist ?
- /edit Dieser Punkt hat sich erledigt dank an http://www.fischer-bayern.de /edit
- Wie kann ich z.B. wenn in der Systemeinstellungen der Hacken auf Ton Aus dies ändern per Appleskript ?
 
Zuletzt bearbeitet:
Skript - Für einen guten Start in den Tag

Falls es dann doch wiedererwarten interessieren sollte:

So erstmal was es kann
- Es begrüßt den Nutzer mit der Systemstimme
- Es prüft ob Itunes schon gestartet wurde und handelt dementsprechend
- öffnet eine Website ( des Browsergames Icewars ) ;-)
- startet Mail und gibt aus wieviele ungelesen Nachrichten

Bugs, oder was es nicht kann
-Itunes status wird nicht abgefragt das bedeutet es erkennt nur ob Itunes gestartet worden ist nicht ob es auf pausing/stopped steht.
-Vereinzelt habe ich beobachtet das Mail abstürtzt.

set theDate to current date
set theTime to time of the theDate
set theDay to weekday of theDate
set d to current date
set derTag to text -2 thru -1 of ("0" & d's day)
set Monat to word 3 of ((current date) as text)
set MonatsListe to {January, February, March, April, May, June, July, August, September, October, November, December}

repeat with i from 1 to 12

if d's month = item i of MonatsListe then
set MM to text -2 thru -1 of ("0" & i)
exit repeat
end if
end repeat


set Jahr to ((year of d) as text)
set dasDatum to theDay & derTag & "." & Monat

-- Datumskonvertierung für say
(* tell application "Finder"
set sound to 0
end tell *)

set probeItunes to false
tell application "System Events"
if process "iTunes" exists then set probeItunes to true
end tell

if probeItunes = true then
tell application "iTunes"
set sound volume to 15
end tell
end if

-- Überprüfung ob Itunes läuft, ggf. Lautstärke anpassen

delay 2

if theTime < 21600 then
say "UP late, o Master of the thousand confusion! It's " & dasDatum & "."
else if theTime < 43200 then
say "Good morning, o Master of the thousand confusion! It's " & dasDatum & "."
else if theTime < 64800 then
say "Good Afternoon, o Master of the thousand confusion! It's " & dasDatum & "."
else
say "Good evening, o Master of the thousand confusion! It's " & dasDatum & "."
end if

-- Ich bin ein Fan von Flinx Foly von Alean Dean Foster ich wollte auch einen Computer der mich begrüßt

if probeItunes = true then
delay 15
tell application "iTunes"
set sound volume to 100
set theTrack to current track
set theTrackName to name of theTrack
set theTrackArtist to artist of theTrack
end tell

tell application "iTunes"
set sound volume to 15
say "This is " & theTrackName & ", by " & ¬
theTrackArtist & ". "
set sound volume to 100
end tell
end if

-- sollte Itunes schon laufen wird nun der Titel

if probeItunes = false then
delay 15
say "I will put some music on"

tell application "iTunes"
activate
set sound volume to 100
set theTrack to some file track of user playlist "Meine Top 25"
set theTrackName to name of theTrack
set theTrackArtist to artist of theTrack
play theTrack
set collapsed of window 1 to true
end tell

tell application "iTunes"
activate
set sound volume to 15
say "This is " & theTrackName & ", by " & ¬
theTrackArtist & ". "
set sound volume to 100
end tell
end if

-- Itunes starten, zufällig wird ein Track aus "Meine Top 25" abgespielt

delay 10

property theURL : "http://www.icewars.de/index.php?action=login&name=XXXXXXXXXX&pswd=XXXXXXXXXXX&submit=1"
open location theURL
delay 30

-- Ja hier könnte auch http://www.spiegel.de stehen.

tell application "Mail"
activate
check for new mail

delay 60
set unreadCount to unread count of inbox
tell application "iTunes"
set sound volume to 15
delay 1
if unreadCount is equal to 0 then say ¬
"You have no new messages!"
if unreadCount is equal to 1 then say ¬
"You have a new message!"
if unreadCount is greater than 1 then say ¬
"You have " & unreadCount & " new messages!"
delay 1
set sound volume to 100
end tell
end tell
-- Mail unread count mit Ansage.
 
Sehr cooles Script! Auch gut durchdacht.
Ich hab was ähnliches bei mir am laufen und ebenfalls das iTunes-Status-Abfrage-Problem:
Hab einen Funkwebserver am LAN dran, der per Funk meine Steckdosen im Haus steuern kann. Per AppleScript steuere ich den an.
Mit BluephoneElite wird erkannt, ob mein Handy außerhalb der Bluetooth-Reichweite ist.

Wenn ich das Haus verlasse verabschiedet mich mein Script, fragt in einem Dialog ob alle Geräte ausgeschalten werden sollen oder nicht (falls ich das Script mal manuell starten sollte und den Dialog also auch verwenden könnte *g*), nach einer bestimmten Zeit übernimmt er dann die Eingaben und fährt langsam Stück für Stück die Lampen herunter, schaltet alle elektronischen Geräte aus, stoppt iTunes und schickt mir dann per eMail schließlich ne Bestätigung an mein Handy, dass alles ordungsgemäß ausgeschaltet wurde.

Große Spielerei, aber macht Spaß :)

Aber es wäre eben schön, wenn das Script vorher abfragen würde, ob iTunes schon läuft oder nicht. Denn so startet es nach meiner "Rückkehr" in die Bluetooth-Reichweite eben IMMER iTunes, egal ob es vorher gelaufen ist oder nicht. Und manchmal möchte man das ja nicht...
 
Die Kontrolle welche Anwendungen aktiv sind könnt ihr mit System Events durchführen:
Code:
tell application "System Events"
	set allProcesses to every process
	set processNames to {}
	repeat with aProcess in allProcesses
		set n to name of aProcess
		set end of processNames to n
	end repeat
	if "iTunes" is in processNames then
		display dialog "iTunes läuft."
	else
		display dialog "iTunes ist inaktiv"
	end if
end tell

Hope it helps
Farid
 
Das hatte ich auch schon probiert, aber das Problem ist, dass ich iTunes ja nicht beenden will, nur stoppen bzw. auf Pause stellen. Das ist ja gleichzeitig noch der Musikserver, der ja anbleiben soll und er soll regelmäßig die Podcasts usw. weiter aktualisieren, auch wenn ich nicht da bin. Also nur Pause machen und danach wieder genau da weiterspielen, wo er aufgehört hat. Und wenn iTunes eben nicht auf Play war, dann eben auch nicht wieder anfangen zu laufen.
Durch diese Statusabfrage könnte man dann auch endlich scripten, dass er nach ner Playlist oder nem Hörspiel oder so, wenn der Status ja automatisch nicht mehr "play" ist, z.B. ein Script ausführt, dass die Stereoanlage dann ausschaltet....

Trotzdem danke dir.

Aber sowas muss doch irgendwie gehen.... grübel..
 
cyberrib schrieb:
Aber sowas muss doch irgendwie gehen.... grübel..
Sorry, hab dich wahrscheinlich falsch verstanden. Ich glaube damit sollte sich dein Problem lösen lassen:
Code:
tell application "iTunes"
	set s to player state
end tell
player state antwortet entsprechend der iTunes-Aktivität mit playing/paused/stopped

Frohes scripten
Farid
 
Abfrage ob Prozess existiert:

Code:
tell application "Finder"
	process "Mail" exists
	if true then
		set theMailinfo to "Mail is running"
	else
		set theMailinfo to "Mail is not running"
	end if
	process "iTunes" exists
	if true then
		set theiTunesinfo to "iTunes is running"
	else
		set theiTunesinfo to "iTunes is not running"
	end if
end tell

Funktioniert, läuft bei mir regelmäßig zufriedenstellend (als Teil eines größeren Scripts).

Grüße,
Flo
 
Hallo, kennt jemand ein Script oder weiß, wie ich das DVD Laufwerk meines Rechners ansprechen kann? ICh möchte nämlich, dass meine Filme, die ich auf einer DVD habe (im mp4 oder divx Format) automatisch gespielt werden (z.B. von VLC), wenn ich die DVD einlege. Noch besser wäre noch ein Script, dass automatisch von allen Videodateien auf einer DVD Aliase im Ordner "Filme" anlegt, dann könnte man die auch mit den verschiedenen Mediacenter (wie Frontrow, Centerstage oder Mediacentral) abspielen. Diese greifen bei den Videos nämlich immer nur auf den Ordner Filme zu. Danke.
FOLKA
 
Zurück
Oben Unten