Welcome to the MP3Car.com forums.
You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. Registering will also remove advertisements. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!
If you have any problems with the registration process or your account login, please contact contact us.
|
03-27-2007, 04:41 PM
|
#16
|
|
Constant Bitrate
Join Date: Feb 2006
Vehicle: 2002 Mercury Mountaineer
Posts: 125
|
Alarm Clock 2 i use this as my alarm clock and its GREAT. alarm clock 2. it uses itunes library and playlists and stuff but i dont think itunes has to be open but i may be wrong.
|
|
|
03-27-2007, 05:18 PM
|
#17
|
|
Constant Bitrate
Join Date: Jan 2007
Location: Dallas
Vehicle: 99/pontiac/transAm
Posts: 147
|
thats cool. but try that last bit of code and see if that helps your situation. let me know if it does
|
|
|
03-27-2007, 05:28 PM
|
#18
|
|
Newbie
Join Date: Sep 2006
Location: Lynnwood, WA
Vehicle: 1994 Toyota Landcruiser FZJ80
Posts: 2
|
I use SleepWatcher ( bb's Homepage ) to run various Applescripts at sleep and wake. One of them is to start iTunes playing.
BugByte: Can you say more about how the idle loop is unstable? I'm about to start using it to pull values off an Arduino (microcontroller board) and haven't had any problems with the code on my test machine so far. Perhaps the instability will show up when I transfer the new code to the mini in the car.
Cheers,
JFS III
|
|
|
03-27-2007, 06:26 PM
|
#19
|
|
Admin. Don't bug or I'll byte.
Join Date: Sep 2004
Location: Corning, NY
Vehicle: 2001 VW Beetle
Posts: 4,470
|
Quote: Originally Posted by Count_Fred 
BugByte: Can you say more about how the idle loop is unstable? I'm about to start using it to pull values off an Arduino (microcontroller board) and haven't had any problems with the code on my test machine so far.
Well, it becomes a problem when you have a full featured app programmed. What sealed it for us was that when you clicked a button on the screen, it would light up to show clicked, but it would never un-click. Until you pressed it a SECOND time.
The way we had it set up, the idle handler was what got called whenever you pressed a button and then routed the action off to the proper script depending on what screen was displayed. This allowed us to reuse buttons from screen to screen and so forth.
In any case, the idle handler makes it difficult to debug the script because it fires whenever it has time -sometimes in the middle of one of your other scripts running. So the debugger will be following through some code you're trying to debug and then shoots you off to the idle handler over and over. Makes it difficult to debug.
As for the sleep/wake problem, we did solve that pretty easily. You have to program the script as an application. That allows you to read and write preferences. Once you can do that, you can set those prefs according to what's going on with the various apps on the screen or inputs from the keyboard.
We had the same issue of not being able to pause iTunes. You get around it by setting a preference when you click a button onscreen or get some keyboard input. Your application 'sets' that preference to pause, then pauses iTunes. Next time through, you compare the application's pause pref with the iTunes state. If they are BOTH pause, then you stay paused.
Then, when you click the button or hit the key, you set the app's pref to 'play' and next time through, the idle handler compares that to the iTunes state, which is paused. It starts iTunes playing at that point.
I don't think you can read/write pref files through the script editor, although I could be wrong. You have to use XCode to build an applescript application.
|
|
|
04-30-2007, 10:48 PM
|
#20
|
|
Constant Bitrate
Join Date: Jan 2007
Location: Dallas
Vehicle: 99/pontiac/transAm
Posts: 147
|
ok everybody here is a script that i edited to help make itunes a bit more managable in the car. due to a battery issue that i have yet to fix in my car, my mac keeps shutting down instead of sleep so i did some searching and came up with this script and edited it a little. this script helps in the event of a reboot or whatever else that causes itunes to shutdown. it will keep an eye on what song you are currently listening to and then when and if itunes is shutdown it will start it back up playing the same song as before.
ok here it is:
property Song_To_Start : 1
property Plist_To_Start : "Library"
on idle
tell application "iTunes"
if player state is paused then
play
else if player state is playing then
copy (name of container of current track) to Plist_To_Start
copy index of current track to Song_To_Start
else if player state is stopped then
play track Song_To_Start of playlist Plist_To_Start
end if
end tell
return 1
end idle
ok now as before make sure that you save it as an application and that the "stay open" box is checked.
im not a 100% sure that all the bugs are fixed so be forwarned. hope this helps some.
|
|
|
05-02-2007, 04:39 PM
|
#21
|
|
Admin. Don't bug or I'll byte.
Join Date: Sep 2004
Location: Corning, NY
Vehicle: 2001 VW Beetle
Posts: 4,470
|
Does that take advantage of the Applescript feature that it 'remembers' the state when you run it, even if you quit the app and restart it?
If so, cool. Nice use of that feature.
|
|
|
05-02-2007, 07:06 PM
|
#22
|
|
Constant Bitrate
Join Date: Jan 2007
Location: Dallas
Vehicle: 99/pontiac/transAm
Posts: 147
|
yeah it does. the whole reason i wrote the script is because my mini keeps shutting down instead of sleeping (bad battery) and i got tired of having to find the cd that i was playing previously. i think there are still some bugs that i need to work out. so i will continue on with it and post back with any updates
|
|
|
05-02-2007, 08:19 PM
|
#23
|
|
Admin. Don't bug or I'll byte.
Join Date: Sep 2004
Location: Corning, NY
Vehicle: 2001 VW Beetle
Posts: 4,470
|
Good one. How about adding a variable that keeps track of the player head position:
property Track_position: 1
Then use:
copy player position to Track_position
to keep track of where in the song it was and set the player position back to that spot if you reboot.
|
|
|
05-09-2007, 12:29 AM
|
#24
|
|
Constant Bitrate
Join Date: Jan 2007
Location: Dallas
Vehicle: 99/pontiac/transAm
Posts: 147
|
Bugbyte, i have a quick question regarding the behavior of applescript. i have had a week or so now to use and test the script that i posted earlier in this thread, and i have come to notice 2 main bugs to which i don't know how to go about fixing.
the first is when the mini reboots the variables are i guess set to whatever, cause after the boot, itunes launches and a song starts playing. it seems to be just some random song, but now everytime that it reboots it plays that song. now if i am just running itunes listening to music, and i shut down itunes or the script, itunes will restart and resume playing the song that it left off just like it should. so my question is if there is a way to make applescript write the song info to an actual file that is on the harddrive vs ram and then be able to get the song info from that file? because i think it is the ram being cleared during the reboot.
the second issue is that the app keeps timing out. do you know how to work around this?
thanks for any help you can give.
|
|
|
04-21-2008, 07:14 PM
|
#25
|
|
Newbie
Join Date: Apr 2008
Posts: 2
|
Quote: Originally Posted by natedawgg 
ok so i did some reading up on apple script and i finally got bugbyte's code to work. Here is what you need to do to make this work. in script editior enter in
on idle
tell application "iTunes"
if player state is paused or player state is stopped then
play
end if
end tell
return 1
end idle
when you save this file make sure you save the script as an application and then check the "stay open" box at the bottom of the "save as" window.
if you do everything correctly then you can run this app and it will check every second to see if itunes is paused. i checked it on my system and it seems to work great. if you have any problems pm me and i will see if i can help. thanks bug byte for your help on this.
Would It be possible to modify this script so that it would work with:
Quote: Originally Posted by Count_Fred 
I use SleepWatcher ( bb's Homepage ) to run various Applescripts at sleep and wake. One of them is to start iTunes playing.
Maybe replace "on idle" with "on wake" or something? IDK anything about this stuff though.
|
|
|
04-22-2008, 12:43 AM
|
#26
|
|
Admin. Don't bug or I'll byte.
Join Date: Sep 2004
Location: Corning, NY
Vehicle: 2001 VW Beetle
Posts: 4,470
|
There is no 'on wake' in Applescript. On Idle tells the script to perform the commands that follow when it has a spare moment and causes it to keep looping.
If you are sleeping the Mini, the script should suspend until you wake the Mini, so no need for the Sleepwatcher solution.
@Natedawgg - I never saw your question, but that is how Applescript works. It stores the last state that it was shut down in the variables. Very odd behavior. It is possible to read and write plist variables using applescript to keep track of what song and what track position iTunes is on from moment to moment, but I presume since you are writing your own FE now, this isn't a concern anymore!
|
|
|
04-22-2008, 04:00 AM
|
#27
|
|
QCar Creator
Join Date: Jul 2005
Location: Netherlands
Vehicle: 1993 Tatra 613-4Mi Long
Posts: 541
|
Quote: Originally Posted by Bugbyte 
...that is how Applescript works. It stores the last state that it was shut down in the variables. Very odd behavior. ...
I am not 100% sure, but I believe only the contents of the properties (explicitly declared by property keyword) is preserved, not regular variables.
|
|
|
04-22-2008, 12:05 PM
|
#28
|
|
Admin. Don't bug or I'll byte.
Join Date: Sep 2004
Location: Corning, NY
Vehicle: 2001 VW Beetle
Posts: 4,470
|
Jirka is right - again. According to my "Applescript - The Definitive Guide" (which I highly recommend if you want to do anything in AS), scripting components have a memory, or rather, they maintain state. Internal memory of an AppleScript scripting component persists until the application that summoned it quits.
However, variables declared using the property keyword survive the termination of the script.
Try this script to see what I mean:
property x :5
set x to x + 1
display dialog x
Run it and you'll get 6. Run it again and you'll get 7. Doesn't matter that you initialize x to 5 at the start because the property keyword sets a value to a variable that doesn't have a value. Which is why it works the first time. The second time, x already has a value (6), so it doesn't need initializing.
Use the 'set' keyword to both initialize AND set the value you want.
set x to 5
set x to x + 1
display dialog x
Will yield 6 over and over again.
BTW, if you edit the script in Script Editor between runs, you won't get this result. That's because you have altered the script and it has to be recompiled. But if you save the first script as a compiled script file and quit Script Editor, then launch and relaunch your compiled script, you'll see what I mean.
I believe that restarting the machine will wipe the variable persistence and start you back at the original value.
I find it is best to just use 'set' to keep things Kosher. Again, if you want to set plist variables, let me know and I'll post the code.
|
|
|
04-22-2008, 03:52 PM
|
#29
|
|
Newbie
Join Date: Apr 2008
Posts: 2
|
Quote: Originally Posted by Bugbyte 
If you are sleeping the Mini, the script should suspend until you wake the Mini, so no need for the Sleepwatcher solution.
I'm not using this on a mini however. I'm using it on my Macbook pro. When i open it (it wakes) I want it to start playing where it left off with iTunes.
Also i want to be able to manually pause and stop it without closing the script.
|
|
|
04-22-2008, 05:04 PM
|
#30
|
|
Admin. Don't bug or I'll byte.
Join Date: Sep 2004
Location: Corning, NY
Vehicle: 2001 VW Beetle
Posts: 4,470
|
Are you saying that when you run this script and the machine wakes up that it doesn't start iTunes? It should, as long as the script is running.
To manually pause and stop, you have to add code to read and write prefs. Effectively, you have to toggle a pref in response to a key command or on screen button press. Then, you have to check both the iTunes state AND the pref state. If the pref state says you pushed a pause key/button, it drops out of the script. When you toggle that pref again, it restarts iTunes.
|
|
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -5. The time now is 09:31 AM.
|
|