public void StartListener() { observerList.Add(center.AddObserver(new NSString("com.swinsian.Swinsian-Track-Playing"), async obj => { var dict = obj.UserInfo; await Task.Run(() => { var npdict = new Dictionary <string, string>(); npdict.Add(nameof(SongInfo.Title), dict["title"] as NSString); //Can't get this property npdict.Add(nameof(SongInfo.AlbumArtist), ""); npdict.Add(nameof(SongInfo.Album), dict["album"] as NSString); //Can't get this property npdict.Add(nameof(SongInfo.TrackCount), "0"); npdict.Add(nameof(SongInfo.Artist), dict["artist"] as NSString); npdict.Add(nameof(SongInfo.Composer), dict["composer"] as NSString); npdict.Add(nameof(SongInfo.Year), dict["year"] as NSString); npdict.Add(nameof(SongInfo.Group), dict["grouping"] as NSString); var apath = dict["thumbnailPath"] as NSString; npdict.Add(nameof(SongInfo.AlbumArtPath), Path.GetDirectoryName(apath) + "/cover_512.png"); var songinfo = new SongInfo(npdict); }); })); observerList.Add(center.AddObserver(new NSString("com.apple.iTunes.playerInfo"), async obj => { var dict = obj.UserInfo; await Task.Run(() => { var npdict = new Dictionary <string, string>(); npdict.Add(nameof(SongInfo.Title), dict["Name"] as NSString); npdict.Add(nameof(SongInfo.AlbumArtist), dict["Album Artist"] as NSString); npdict.Add(nameof(SongInfo.Album), dict["Album"] as NSString); npdict.Add(nameof(SongInfo.TrackCount), dict["Play Count"] as NSString); npdict.Add(nameof(SongInfo.Artist), dict["Artist"] as NSString); //Can't get those property npdict.Add(nameof(SongInfo.Composer), ""); npdict.Add(nameof(SongInfo.Year), ""); npdict.Add(nameof(SongInfo.Group), ""); //get album art var itunes = SBApplication.FromBundleIdentifier("com.apple.iTunes"); var ctrack = itunes.ValueForKey(new NSString("currentTrack")); var front_artwork = ctrack.ValueForKey(new NSString("artworks")) as SBElementArray; if (front_artwork.Count > 0) { var aitem = front_artwork.Get()[0]; var raw_image = aitem.ValueForKey(new NSString("rawData")) as NSData; npdict.Add(nameof(SongInfo.AlbumArtBase64), raw_image.GetBase64EncodedString(NSDataBase64EncodingOptions.None)); } var songinfo = new SongInfo(npdict); }); })); }
static int Main(string[] args) { FinderApplication app = SBApplication.FromBundleIdentifier <FinderApplication> ("com.apple.finder"); if ((int)app.Trash.Items.Count > 0) { for (int i = 0; i < (int)app.Trash.Items.Count; ++i) { FinderItem item = app.Trash.Items.GetItem <FinderItem> ((nuint)i); if (item.Name == null) { return(0); } } } Console.WriteLine("Passed"); return(0); }
public void TestGetApplicationFromBundleIdentifier() { const string knownBundle = "com.apple.finder"; const string unknownBundle = "com.unknown.bundle"; #if !XAMCORE_4_0 using (var app1 = SBApplication.FromBundleIdentifier(knownBundle)) using (var app2 = SBApplication.FromBundleIdentifier <MySBApp> (knownBundle)) using (var app3 = SBApplication.FromBundleIdentifier(unknownBundle)) using (var app4 = SBApplication.FromBundleIdentifier <MySBApp> (unknownBundle)) #else var(app1 = SBApplication.GetApplication(knownBundle)) var(app2 = SBApplication.GetApplication <MySbApp> (knownBundle)) var(app3 = SBApplication.GetApplication(unknownBundle)) var(app4 = SBApplication.GetApplication <MySbApp> (unknownBundle)) #endif { Assert.IsNotNull(app1, "SBApplication from known bundle is null"); Assert.IsNotNull(app2, "MySBApp from known bundle is null"); Assert.IsNull(app3, "SBApplication from unknown bundle is non-null"); Assert.IsNull(app4, "MySBApp from unknown bundle is non-null"); } }
public override void AwakeFromNib() { base.AwakeFromNib(); // ScriptingBridge Tests // // FinderApplication *finder = [SBApplication applicationWithBundleIdentifier:@"com.apple.finder"]; SBApplication finder = SBApplication.FromBundleIdentifier("com.apple.finder"); // SBElementArray *disks = [finder disks]; IntPtr disks = Messaging.IntPtr_objc_msgSend(finder.Handle, Selector.GetHandle("disks")); //FinderDisk *disk = [disks objectAtIndex:0]; IntPtr disk = Messaging.IntPtr_objc_msgSend_int(disks, Selector.GetHandle("objectAtIndex:"), 0); // NSString *name = [disk name]; // lazy evaluation occurs IntPtr name = Messaging.IntPtr_objc_msgSend(disk, Selector.GetHandle("name")); string strname = new NSString(name); // NSLog(@"Name of first disk is %@", strname); Console.WriteLine("Name of first disk is {0}", strname); // iTunes SBApplication iTunes = SBApplication.FromBundleIdentifier("com.apple.iTunes"); // Get Volume IntPtr ptrVol = Messaging.IntPtr_objc_msgSend(iTunes.Handle, Selector.GetHandle("soundVolume")); int vol = (int)ptrVol; // Show Volume to console Console.WriteLine("Volume: {0}", vol); lblVolume.StringValue = String.Format("Volume: {0}", vol); // in app label sliderVolume.TickMarksCount = 101; // set the number of "stops" sliderVolume.IntValue = vol; // Set the slider value based on the volume sliderVolume.AllowsTickMarkValuesOnly = true; // Allow only integral numbers // Handle slider dragging (must check "continuous" in xib) sliderVolume.Activated += (object sender, EventArgs e) => { var pos = sliderVolume.IntValue; // Get slider value Console.WriteLine("SetVol = " + pos); //Show volume in console Messaging.IntPtr_objc_msgSend_int(iTunes.Handle, Selector.GetHandle("setSoundVolume:"), pos); // Set volume in iTunes lblVolume.StringValue = String.Format("Volume: {0}", pos); // show volume in label }; // Handle button clicks btnPrevTrack.Activated += (object sender, EventArgs e) => { Messaging.IntPtr_objc_msgSend(iTunes.Handle, Selector.GetHandle("previousTrack")); btnWhatsPlaying.PerformClick(this); }; btnNextTrack.Activated += (object sender, EventArgs e) => { Messaging.IntPtr_objc_msgSend(iTunes.Handle, Selector.GetHandle("nextTrack")); btnWhatsPlaying.PerformClick(this); }; btnWhatsPlaying.Activated += (object sender, EventArgs e) => { // get pointer to current track object IntPtr ptr = Messaging.IntPtr_objc_msgSend(iTunes.Handle, Selector.GetHandle("currentTrack")); IntPtr ptrTitle = Messaging.IntPtr_objc_msgSend(ptr, Selector.GetHandle("name")); // use pointer to track object to get song name IntPtr ptrArtist = Messaging.IntPtr_objc_msgSend(ptr, Selector.GetHandle("artist")); // artist IntPtr ptrAlbum = Messaging.IntPtr_objc_msgSend(ptr, Selector.GetHandle("album")); // and album string song = new NSString(ptrTitle); // convert pointers to strings string artist = new NSString(ptrArtist); string album = new NSString(ptrAlbum); Console.WriteLine("iTunes Song Playing: Artist: {0}, Album: {1}, Title: {2}", artist, album, song); // show in console lblArtist.StringValue = String.Format("Artist: {0}", artist); // Show in app labels lblAlbum.StringValue = String.Format("Album: {0}", album); lblSong.StringValue = String.Format("Song: {0}", song); }; }
public override void AwakeFromNib() { applicationsTable.Target = this; finder = SBApplication.FromBundleIdentifier("com.apple.finder"); }