I'm wanting to make a AppleScript to give me the current track name playing on itunes. So far I have made it get the name and refresh after the song has played with duration of the song.
Delay Song_duration
What I'm getting a problem is if the user skips the song manually or changes the song; I can see the are events called "next track" and "previous track" but it seems you can't do stuff like:
if (next track) then
because it does the event in the brackets. What I'm wanting to know is if there is a way to listen for the event. I don't know much about AppleScript, just been looking online for answers.
The general gist of the script is I want to get the name of the track and artist instantly with as little CPU/Memory as possible or I would just do delay 1.
Basically you can't do it with applescript.
iTunes sends out a system wide notification whenever it's state changes called "com.apple.itunes.playerInfo". So you need to write in a language that can receive system notifications, objective-c for example. In that language you register for system notifications under the NSDistributedNotificationCenter. Once registered your program would run in the background, using little to no system resources, and then whenever something changes in iTunes your program would receive a notification and then you do something with iTunes.
Here's a link to a similar question and a couple solutions are posted.
Related
By default, VLC will keep the songs that were played in the last session as part of the playlist. I have an AppleScript that plays music that is stored as MP3 files in a folder.
tell application "VLC"
set thePlaylist to "file:////Users/[username]/Music/Playlist"
OpenURL thePlaylist
end tell
Since VLC stores the last songs, it will start playing from wherever the song was last and then play from this playlist afterwards.
I've tried a couple of commands, but I haven't been able to clear the playlist from my AppleScript.
Short answer: you can't do this through AppleScript. VLC's scripting dictionary is only a list of verbs — actions that can be performed on the current playing item — it has no nouns or object references that would let you specify things like 'playlists', 'videos', 'tracks', etc. There is no way to 'talk' to VLC about anything other than the currently queued item.
That might be something to report to VLC's developer. It's a weak AppleScript dictionary.
You might be able to fix this in VLC's Preferences. Looking at the full settings in VLC (click the "Show All" button at the bottom left) the two I highlighted seem like the might give you some control. There might be other setting that I didn't see; you should look through the options.
I'm brand new to Apple Script and trying to write a simple script that, while running, logs a timestamp any time the mouse is clicked anywhere.
How can I detect/listen for mouse events, and execute a command (logging a date-time) when they happen?
(This seems to me like a pretty basic thing to try to do, but I may be misunderstanding what AppleScript is for.)
Mouse-clicks are events handled and distributed by the system. In order to capture them you'd need to set up an event monitor, but there are no hooks for that in vanilla AppleScript; the language isn't designed for it.
If you wanted to switch to AppleScriptObjC and create an application, you could certainly set up an event monitor of this sort (using something like NSEvent's addGlobalMonitorForEventsMatchingMask:handler:. But I doubt AppleScript is the best language for it. At least, I can't think of a compelling reason to do this in AppleScript as opposed to writing a small cocoa app, and I anticipate a number of headaches trying to make the callback work correctly.
I figured I'd ask here and see if anyone could offer anything, you guys are the faster answerers of anything. By default, when you hide a calendar in iCal (Snow Leopard) (clicking the checkbox), by default, every event is still armed. Like the alarms for hidden events will still activate at those times. I'd like them to turn off as long as the calendar is hidden. Is there maybe an applescript way to accomplish this?
Right now I'm trying a new anti-lazy workflow where I schedule tasks for myself ahead of time and force myself to switch to them (instead of saying "i'll do it later") by having the alert for each event be to activate a program that locks me out of my computer for 3 mins (Time Out). So far it's working well but being able to switch alarms on and off that quickly would really help.
Thanks!
Edit: I know you can right click and go to a dialog that turns off all alarms for that calendar, but it's so easy to forget to do that.
EditEdit: While we're at it, is there a way to move multiple events at once? You'd think this would be a given, but instead it just makes one new event where you dragged.
I want to write a script that takes action when a document is opened on a certain application, or before an application quits, etc.
Is there a way to attach a script to an event in an application? Does AppleScript support any form of hooks at all?
If not, can I hack my way into getting what I want?
applescript only has certain "event listeners" the are folder action script that might be considered an event listener and indesign has real event listeners which I won't get into at the moment.
if you want a blanket listener for any application to quit you may find what your looking for in a Quickeys though I'm not certain of this as it has been a long time since I have messed around with quickeys.
but all and all the answer is for the most part no.
hth
Mike
EDIT more tools that may help brought by kch
FastScripts
QuickSilver
Keyboard Maestro
"Some apps, eg. iChat, have script hooks in the preferences. In iChat, the Alerts preference pane, you can set it to run a script when a certain event is triggered, like message received, file transfer request, etc." – kch
I want to respond to a certain type of new window being opened by an external application. I have some experience finding applications and windows currently open (system wide) using some of the carbon functionality, so could theoretically just check every few seconds. This would require getting a list of all open windows and checking it against some list I would have to maintain, and feels very clunky.
How can I get a simple, clean notification when a new window is launched? Should I use the accessibility API? If so, what specifically am I looking for?
First, create an AXObserver. Then, watch for launches of any applications that you think you'd be interested in. When such a launch occurs, create an application AXUIElement for that process, and add your observer to it for the kAXWindowCreatedNotification notification.
I question whether this is the best way to do whatever you're trying to do. You might step back a bit from this solution (that is, watching for new windows) and ask another question about your goal.