ncmpcpp stops highlighting current song - bash

Hi I'm recently working around with ncmpcpp and I've configured it pretty nicely to what I want. Unfortunately on playlist view, after 3-4 seconds it will stop highlighting the currently played song, and as a result I lose track of where I am in my playlist (even though the song is played in the header).
Is there a way to have the currently played song constantly highlighted? I've looked through the numerous ncmpcpp config options and I couldn't find something to this.
Here's a gif of what is happening:
http://i.imgur.com/9eCOLyj.gif
Here is the config file for ncmpcpp: http://pastebin.com/XTdQa2qb
Here is the config file for mpd:
music_directory "~/Music/albums"
playlist_directory "~/.mpd/playlists"
db_file "~/.mpd/mpd.db"
log_file "~/.mpd/mpd.log"
pid_file "~/.mpd/mpd.pid"
state_file "~/.mpd/mpdstate"
auto_update "yes"
auto_update_depth "2"
audio_output {
type "osx"
name "aMat Mac Device"
mixer_type "software"
}
audio_output {
type "fifo"
name "my_fifo"
path "/tmp/mpd.fifo"
format "44100:16:2"
}
bind_to_address "localhost"

Well lesson learned, always read the man page!
There's a ncmpcpp config option playlist_disable_highlight_delay = 0 which solves the issue of the highlighting fading away. When you set it to 0 it will stay highlighted forever.
Although what would be ideal would be if I could highlight other parts of my playlist and still have some indicator on what is currently playing. But c'est la vie, this is a solution.

Related

I'm creating a little sound that plays when your mouse hovers over the button "White team" but nothing really happens. I'm using the MouseEnter event

I have been trying to create a sound every time your mouse leaves and enters this button. The code doesn't really work. I have tried this on a local script and a normal script:
script.Parent.MouseEnter:Connect(function()
local sound = script.Parent.Parent.hit
sound:Play()
end)
script.Parent.MouseEnter:Connect(function()
local soundTwo = script.Parent.Parent.hitS
soundTwo:Play()
end)
```[enter image description here][1]
[1]: https://i.stack.imgur.com/5niz4.png -- The explorer of the game (I used script and local script btw and none of them changed anything, but i do think local script would work better for a gui)
You can try adding the following lines at the top of your code.
if not sound.IsLoaded then sound.Loaded:Wait() end
if not soundTwo.IsLoaded then soundTwo.Loaded:Wait() end
Also, both of your functions are for MouseEnter. Try changing one to MouseLeave.

Change video player position with AppleScript?

I have got a problem and I really don’t know how to solve it: I would like to change the player position of this / this video while it is opened in the background (so that another tab or application can be active at the same time). I can’t find anything helpful in the sourcecode and GUI scripting is not an option.
Thank you in advance!
EDIT: I came up with an idea: I changed the user agent to iOS 10 (iPhone) although I’m not sure if this makes the whole thing easier.
You can do this with AppleScript and JavaScript if the video player is using the HTML5 video tag. Like you said, changing your user agent to an iOS device increases your chances of being served this instead of a flash player.
First, you need to search for the correct window by URL. Then, the script will run some Javascript in the window to update the time of the video. Change the properties to fit your usage. If the page has multiple video tags, you can change the [0] to which one by order on the DOM, or target by ID instead.
property checkURL : "vimeo.com"
property changeTime : 90
try
tell application "Safari"
set theTab to first tab of window 1 whose URL contains checkURL
do JavaScript "document.getElementsByTagName('video')[0].currentTime = " & changeTime in theTab
end tell
on error
display dialog "That site is not loaded"
end try

Cannot play album with AVAudioPlayer

I'm working on a very simple OSX application that will allow me to play either a song or a folder of songs.
I can choose a song and play it and everything is fine. I can choose a folder and create an array of songs and... play the last one.
var currentSong: NSURL?
var album: [NSURL] = []
var audioPlayer = AVAudioPlayer()
My playing function is
func playCurrent(){
do {
try audioPlayer = AVAudioPlayer(contentsOfURL: currentSong!)
} catch {
print("Ignoring errors for now")
}
audioPlayer.play()
}
This works fine whenever I set currentSong to a NSURL. I choose one song, it plays it.
My album function is as follows:
#IBAction func chooseAlbumAndPlay(sender: AnyObject) {
album = albumFromFile()
for song in album {
currentSong = song
playCurrent()
}
}
and here I have the problem. albumFromFile opens an NSOpenPanel, lets me choose a folder, and dumps paths to playable items into an array of NSURLs. This part works, I've verified it, so I really have an array with 12 or 20 or whatever correct, playable URLs. If I just run it as is, only the last song in any album gets played. If I set a breakpoint in the playCurrent() function, I can hear that it will actually play a tiny snippet - less than a note in most cases - of all songs but the last.
According to the documentation, play() returns a boolean - and it will happily report that it has finished playing every song in this loop.
My - human - opinion is that a song has only finished playing when I have heard all of it.
If I query the duration of the current AVAudioPlayer, they all report perfectly reasonable-sounding values.
I'm completely stumped here. PlayCurrent seems to completely fail to assert itself as a running function. The expected behaviour is that it will not exit until play() has finished playing; observed behaviour is that it will touch every song for the briefest time, go 'been there' and return to the enclosing loop.
How can I force AVAudioPlayer to play the whole of a file before exiting my playCurrent() function? And where would I have found that information? (The class documentation is unhelpful, the mentioned audio guides do not exist - right now, the Developer Library does not mention any basic audio guides for OSX.
The answer is, once you get around to it, very obvious indeed. Unfortunately, the documentation really is no help at all. I could, in theory, have found the solution by looking at the entry for AVAudioPlayer in the AVFoundationFramework reference, but I didn't. (I found it by wildly casting about and a chance mention).
There appear to be no working OSX examples; Apple's iOS example uses the MediaPlayer framework that is not available on OSX.
The solution is as follows:
An AVAudioPlayer plays a single sound.
If you want to play more than one sound, you need an AVQueuePlayer which can also play a single sound from a URL or a queue of AVPlayerItems (this class has an init(URL:) method).
If anyone has an idea why AVAudioPlayer behaves as it does, I'm still interested to hear it.

How can I be notified that a movie has been determined not to be a movie?

I'm writing a Mac app that plays MPEG-4 movies using AVPlayer.
My app supports both local movies and movies from the internet, via an “Open Location” dialog. In the latter case, when the user enters a URL and presses the OK button, my app opens the URL as a document.
Local files are easy—Launch Services will tell Finder, Dock, etc. not to light my app up for any local file that isn't a .mp4 or similar. If the user forces my app to open some random file (e.g., by holding down ⌘ when dragging it onto my app), that's their own fault.
Non-local (e.g., internet) URLs are the problem. If I supply a URL that doesn't lead to an MPEG-4, I need to show an alert and close the document.
Of course, I'm not downloading the URL myself; I just hand it to AVPlayer.
So I need a way to be notified by my AVPlayer that what I've given it is not a movie.
I've tried observing the player's status. That gets set to AVPlayerStatusReadyToPlay.
I've tried observing the player's currentItem's tracks. At least on Lion, for an invalid movie, the item's tracks never changes. (This stands to reason—the only reason it would change would be tracks coming in, which is, by definition, impossible for a non-movie.)
I can't just check tracks when status changes, because that may not be set yet (on Mavericks, status changes before tracks).
So, how can I be notified by my AVPlayer that it has conclusively determined that what the URL refers to is not anything it can play?
It's absolutely not definitive, but in my experience, when the player's status becomes AVPlayerStatusReadyToPlay, you can inspect the playable property of asset of the player's currentItem. If playable is YES, you can assume the URL led to a viable MP4. If not, you can assume it did not.
- (void) observeValueForKeyPath:(NSString*)keyPath
ofObject:(id)object
change:(NSDictionary*)change
context:(void*)context
{
if( [keyPath isEqualToString:#"status"] ) {
if( self.player.status == AVPlayerStatusReadyToPlay &&
self.player.currentItem.asset.playable ) {
[self.playerView.player play];
}
else {
// TODO: show an error dialog here.
[self.window close];
}
}
}
I've code similar to the above in one of my apps, and it seems to work as expected in every case I've tried. I can whip up a test app with it if you like.

OSX Lion AppleScript : How to get current space # from mission control?

I'm trying to figure out how to get the current space # from mission control. Source would be helpful, but more helpful would be info on how to figure this out myself. I've written a few applescripts, but more often than not it seems like any time I need to do something new (that I can't find dictionary documentation for) it falls under the category of "tell this specific app (e.g. "System Events") this very specific thing" and I've no clue how I would actually figure that out.
Specifically what I am trying to do:
I hate the new mission control in OSX 10.7. I want my spaces "grid" back since I used it all the time. I used to navigate between spaces using arrow keys (e.g. ALT+↑) every few seconds. Now I'm stuck with this clunky 1x9 array of spaces instead of an elegant 3x3 grid. I've re-mapped all my spaces to use the number pad, which partially takes care of the problem (since it is a 3x3 grid), but only when I have an external keyboard attached.
Basically, I want to be able to use ALT+↑ and ↓ again, but to do so I need to detect the current space # so that I can switch from space 5-->2, for example.
Dave's answer below, although far more detailed than I expected, requires writing an app to do this (plus it still doesn't fully answer the question). If it's at all possible, I'd rather just bind a few keys to an applescript.
I'm trying to figure this out myself. Not there yet, but in the right direction:
Each Mission Control "space" gets a uuid assigned to it...
...except for the very first one (AFAIK), and the Dashboard one.
You can read them here:
$ defaults read com.apple.spaces
$ defaults read com.apple.desktop
File locations:
~/Library/Preferences/com.apple.spaces.plist
~/Library/Preferences/com.apple.desktop.plist
Here's mine. I have four spaces enabled, and three entries show up:
$ defaults read com.apple.spaces
{
spaces = (
{
type = 0;
uuid = "9F552977-3DB0-43E5-8753-E45AC4C61973";
},
{
type = 0;
uuid = "44C8072A-7DC9-4E83-94DD-BDEAF333C924";
},
{
type = 0;
uuid = "6FADBDFE-4CE8-4FC9-B535-40D7CC3C4C58";
}
);
}
If you delete a space, that entry will get removed from the file. If you add a space, an entry will be added. Again, there's never an entry for Desktop 1 or Dashboard.
I'm not sure if there's a public API to figure out what space uuid is being displayed on a display. I'd assume that no uuid means Display 1, and the others' mean Display 1+n.
I took a quick glance through the AppleScript Editor Library (Window ---> Library) and didn't see any entries under System Events for spaces. This is probably something that can be done with Cocoa, perhaps via private API, but I'm not sure about AppleScript.
UPDATE - July 23, 2011
It looks like Dock controls Mission Control. You can grab its header files like so:
Go to: /System/Library/CoreServices/Dock
Right-Click and Show Package Contents
Navigate: /Contents/MacOS/
Copy and paste the Dock binary to your desktop.
Run: $class-dump ~/Desktop/Dock
That'll spit out all of its header files (it's long; almost 7,500 lines). You can see the spaceUUID strings appearing in there. There's a class called WVSpace which appears to represent a single Space in Mission Control, and a lot of other WV* classes.
I'll keep looking at it tomorrow; too tired now. :)
UPDATE - July 24, 2011
Inside Dock there's a class called WVSpaces. It has a number of attributes including:
WVSpace *currentSpace;
unsigned int currentWorkspace;
WVSpace *nextSpace; // Space on the right???
WVSpace *previousSpace; // Space on the left???
BOOL currentSpaceIsDashboard;
BOOL dashboardIsCurrent;
...lots more...
Each WVSpace class has an NSString *_uuid; attribute, which is likely its SpaceUUID. So theoretically you can get the current space number like so:
WVSpace *currentSpace = [[WVSpaces sharedInstance] currentSpace];
NSString *currentSpaceUUID = [currentSpace _uuid]; // Empty string if main space???
The trick is, how to get access to the private WVSpaces class buried inside of Dock? I'm assuming it's Singleton as it has an NSMutableArray *_spaces; attribute, probably with every space listed in it. Only one space gets displayed at a time (this holds true if you're using multiple monitors; the space spans across both of them), so it makes sense to only have one WVSpaces instance.
So it looks like it'll require some SIMBL hacking of Dock to gain access to WVSpaces.
I've been poking around, and I came up with this: https://gist.github.com/1129406
Spaces have a nonsequential ID and a sequential index (0-based). You can get the ID in two ways:
from public APIs (see get_space_id)
from the private CGS API CGSGetWorkspace
You can set the current space by index using public APIs (though the notifications themselves are not publicly documented): see set_space_by_index
You can set the current space by ID using private the CGS API CGSSetWorkspace.
You cannot get the current space index directly. However, if you're always using the same set of nine spaces, you can rotate through them once using set_space_by_index, collect their IDs, and build a mapping. Then you will be able to get the current index from the ID.
... also been working on this :)
You say that you "need to to detect the current space #". This is not strictly true: To move down one row, you just move 3 spaces right, so in principle you could just bind something like
tell application "System Events" to tell process "WindowServer"
key code {124, 124, 124} using control down
end tell
to Alt-down (with FastScripts, Alfred or some other fast method that avoids the overhead of Automator). This approach will fail if you ever hit down in the bottom row, of course -- but if you are truly hard-wired, you never do :)
You have to "Enable access for assistive devices" in the Universal Access preference pane for the key code approach to work.
Caveat: This doesn't work. When I launch the script above, I nicely jump three spaces. The problem is that afterwards my keyboard goes unresponsive: It seems that only the window manager is receiving events: I can close windows and switch space, but I cannot interact with any applications.
My theory is that this happens when the jump causes the current application to change during the execution of the script -- but I have no idea how to fix this.
A related observation: The Mission Control (i.e. /Applications/Mission Control.app/Contents/MacOS/Mission\ Control) seems to react to some command line arguments:
Mission\ Control: show mission control
Mission\ Control 1: show desktop
Mission\ Control 2: show current application windows
I tried putting in some of the UUID's from defaults read com.apple.spaces, but that didn't do much. So much for fumbling in the dark.
I wrote an app - does it work for you?
Change Space.app
The keys to make it work are control-shift and the arrow keys, although this may be fixable if you are stuck on ALT.
Make sure you have 9 spaces (desktops) set up before you start, and you'll need to change the default ctrl-up and ctrl-down key bindings in System Preferences to something else (in Keyboard -> Keyboard Shortcuts -> Mission Control : Mission Control and Show Desktop).
On the first run it it will cycle through your desktops to enumerate them when you first change space.
Then you should be able to change between desktops like in a 3x3 grid.
There may be a few wrinkles, but it's basically functional, at least for me.
http://switchstep.com/ReSpaceApp
This works, is free (right now) and is awesome.
Just be sure to manually create as many spaces as your layout (in preferences) is expecting.
I'm on Mountain Lion and this seems to work for me.
defaults read com.apple.spaces
Look for "Current Space". You'll notice that running this command with different active spaces doesn't change the current space BUT if you check and uncheck a checkbox button in "System Preferences" and run it again, you'll see it updated.
Hopefully this helps someone else!
EDIT: It's ugly, but I'm using this:
killall Dock && sleep 0.2 && defaults read com.apple.spaces | grep -A1 "Current Space" | tail -1 | awk '{print $NF }' | cut -f1 -d';'
on openNewSpace()
tell application "System Events"
—start mission control
do shell script "/Applications/Mission\\ Control.app/Contents/MacOS/Mission\\ Control"
tell process "Dock"
set countSpaces to count buttons of list 1 of group 1
--new space
click button 1 of group 1
--switch to new space
repeat until (count buttons of list 1 of group 1) = (countSpaces + 1)
end repeat
click button (countSpaces + 1) of list 1 of group 1
end tell
end tell
end openNewSpace
I have come up with a workaround for this for myself in macOS Catalina, though I expect this should work for multiple macOS versions. This solution solves my problems, namely:
The inability to identify which desktop contains which project, because desktops cannot be named. (I usually am splitting time on work on multiple projects at once and each desktop is dedicated to work on a different project [and they all use the same apps])
The inability to programmatically(/easily) determine which desktop I'm on at any one time
The lack of tools to track time spent on each desktop
I solved item 1 quite some time back using Stickies.app. I put the project name in a huge enough font that it's easily legible in the desktop thumbnails in Mission Control and I hide the stickie window behind my Dock, assigned specifically to the corresponding project's desktop. (I also duplicate the desktop name in small superscripted text that pokes out from under the left side of the dock so that I can identify the current desktop outside of mission control.)
I just solved item 2 via applescript just now. In the stickie, I add a tiny, unobtrustive font string that identifies the stickie as the desktop name, e.g. 'dtop'. E.g. "small_superscripted_name LARGE_NAME tiny_dtop_string" or "project1 PROJECT1 dtop". Note, this script assumes that the project name contains no spaces (i.e. it's just one word). You can split on a different charcter/string, if you wish. Here is the applescript that, when run, results in the desktop name:
tell application "System Events"
--obtain the stickie with the desktop name
set dstr to name of first item of (windows of application process "Stickies" of application "System Events" whose name contains "dtop")
--Parse the desktop name from the stickie
set astid to AppleScript's text item delimiters
set AppleScript's text item delimiters to " "
set dname to first item of (dstr's text items)
set AppleScript's text item delimiters to astid
--Show the result in a dialog window
display dialog "Desktop: " & dname
end tell
And as far as item 3 goes, I have yet to implement it, but I could easily poll via a cron job by calling the script using osascript. However, I may explore the possibility of mapping the desktop keyboard shortcuts I use to trigger the script, say, after a delay like 1 second after a control-right/left-arrow, 10 seconds after F3 or control-up-arrow. (It wouldn't catch window-drags that trigger desktop changes, but that hasn't worked anyway since I started using 2 monitors.)
Once I have that set up, I'll likely output the desktop name and a timestamp to a log so I can track time spent on each desktop.
UPDATE: I did eventually solve item 3 with an Applescript run once a minute in a cron job. I also wrote a perl script to generate a bar plot of both: how much time spent on each project (i.e. desktop) over a period of time (e.g. the past week), and a per day plot showing how much time I spent on what projects each day. Here's an example:

Resources