public void HandleAppleEvent(NSAppleEventDescriptor evt, NSAppleEventDescriptor replyEvt) { var url = evt.ParamDescriptorForKeyword(DirectObject).StringValue; var uri = new Uri(url); OpenUrl(WebUtils.GetNativeUrl(uri)); }
public NSAppleEventDescriptor ExecuteAppleEvent(NSAppleEventDescriptor @event, out NSDictionary errorInfo) { NSAppleEventDescriptor result; IntPtr errorInfoHandle = Marshal.AllocHGlobal(4); if (IsDirectBinding) { result = (NSAppleEventDescriptor)Runtime.GetNSObject(Messaging.IntPtr_objc_msgSend_IntPtr_IntPtr(base.Handle, Selector.GetHandle("executeAppleEvent:error:"), @event.Handle, errorInfoHandle)); } else { result = (NSAppleEventDescriptor)Runtime.GetNSObject(Messaging.IntPtr_objc_msgSendSuper_IntPtr_IntPtr(base.SuperHandle, Selector.GetHandle("executeAppleEvent:error:"), @event.Handle, errorInfoHandle)); } if (result == null) { IntPtr errorInfoHandle2 = Marshal.ReadIntPtr(errorInfoHandle); errorInfo = (NSDictionary)Runtime.GetNSObject(errorInfoHandle2); } else { errorInfo = null; } Marshal.FreeHGlobal(errorInfoHandle); return(result); }
void GetUrlWithReplyEvent(NSAppleEventDescriptor @event, NSAppleEventDescriptor replyEvent) { // from /System/Library/Frameworks/CoreServices.framework/Versions/A/Frameworks/AE.framework/Versions/A/Headers/AppleEvents.h const uint keyDirectObject = 757935405; // '----' const uint keyErrorNumber = 1701999214; // 'errn' const uint keyErrorString = 1701999219; // 'errs' string errorMessage = null; var urlString = @event?.ParamDescriptorForKeyword(keyDirectObject).StringValue; if (urlString != null) { SessionDocumentController .SharedDocumentController .OpenDocument(new NSUrl(urlString)); applicationShouldOpenUntitledFile = false; } replyEvent.SetParamDescriptorforKeyword( NSAppleEventDescriptor.DescriptorWithInt32(errorMessage == null ? 0 : 1), keyErrorNumber); if (errorMessage != null) { replyEvent.SetParamDescriptorforKeyword( NSAppleEventDescriptor.DescriptorWithString(errorMessage), keyErrorString); } }
private void HandleOpenURL(NSAppleEventDescriptor evt, NSAppleEventDescriptor replyEvent) { Log.Information("Handling Open URL Event"); for (int i = 1; i <= evt.NumberOfItems; i++) { var innerDesc = evt.DescriptorAtIndex(i); //Grab the URL if (!string.IsNullOrEmpty(innerDesc.StringValue)) { //Get a hold of the Main Application View Model Log.Information($"Got URL:{innerDesc.StringValue}"); this.mainWindow = AvaloniaLocator.Current.GetService <MainWindow>(); var mwvm = (MainWindowViewModel)this.mainWindow.DataContext; //Get a hold of the currently loaded Model (main menu) if (mwvm.Content.GetType() == typeof(MainMenuViewModel)) { var mmvm = mwvm.Content as MainMenuViewModel; //If there is a Loaded Identity then Invoke the Authentication Dialog if (mmvm.CurrentIdentity != null) { Log.Information($"Open URL Data: {innerDesc.StringValue}"); mmvm.AuthVM = new AuthenticationViewModel(new Uri(innerDesc.StringValue)); mwvm.PriorContent = mwvm.Content; mwvm.Content = mmvm.AuthVM; Dispatcher.UIThread.Post(() => { (Application.Current as App).RestoreMainWindow(); }); } } } } }
public override void ViewDidMoveToWindow() { base.ViewDidMoveToWindow(); TrackName.StringValue = currentDelegate.controller.Track; ArtistName.StringValue = currentDelegate.controller.Artist; if (currentDelegate.controller.App == "iTunes") { PlayerIcon.Image = new NSImage("icon_itunes.pdf"); script = new NSAppleScript(File.ReadAllText("Scripts/GetAlbumArtiTunes.txt")); result = script.ExecuteAndReturnError(out errors); NSImage cover = new NSImage(result.Data); AlbumArtView.Image = cover; ThumbnailView.Image = cover; } else { PlayerIcon.Image = new NSImage("icon_spotify.pdf"); script = new NSAppleScript(File.ReadAllText("Scripts/GetAlbumArtSpotify.txt")); result = script.ExecuteAndReturnError(out errors); NSUrl artworkurl = new NSUrl(result.StringValue); NSImage cover = new NSImage(artworkurl); AlbumArtView.Image = cover; ThumbnailView.Image = cover; } }
//itunesへApplescriptでリクエストを送信して結果を返す関数 private NSAppleEventDescriptor Requesttoitunes(String _script) { NSAppleScript appleScript = new NSAppleScript(_script); NSDictionary error; NSAppleEventDescriptor result = appleScript.ExecuteAndReturnError(out error); return(result); }
public void GetUrl(NSAppleEventDescriptor evt, NSAppleEventDescriptor withReplyEvent) { passedUrl = evt.ParamDescriptorForKeyword(FourCC("----")).StringValue; if (isLoaded) { invoke.Invoke(LoadPassedUrl); } }
public void MonoApplication_HandleURLEvent(NSAppleEventDescriptor value, NSAppleEventDescriptor reply) { var url = value.ParamDescriptorForKeyword(AEKeyword.DirectObject)?.StringValue; if (url != null) { TryOpen(new string[] { url }, Msg.WM_OPEN_URLS); } }
public static bool UrlHandleEvent(NSAppleEventDescriptor evt, NSAppleEventDescriptor replyEvt) { foreach (var item in callBacks) { var s = item.Value(evt, replyEvt); if (s) { return(true); } } return(false); }
//現在再生中のトラック名取得関数 public String GetTrackName() { String script = string.Format("tell application \"{0}\" to get name of current track", this.name); NSAppleEventDescriptor result = Requesttoitunes(script); if (result == null) { return("Null"); } return(result.StringValue); }
public void HandleGetURLEvent(NSAppleEventDescriptor appleEvent, NSAppleEventDescriptor reply) { // Received event is a list (1-based) of URL strings for (int i = 1; i <= appleEvent.NumberOfItems; i++) { NSAppleEventDescriptor innerDesc = appleEvent.DescriptorAtIndex (i); string url = innerDesc.StringValue; if( url != null ) { Program.Controller.FetchInviteFromURL( url ); } } }
void GetCurrentSelectedSolutionPath(NSAppleEventDescriptor @event, NSAppleEventDescriptor reply) { LoggingService.LogInfo($"{nameof (GetCurrentSelectedSolutionPath)}: received AppleEvent {@event}"); var solutionPath = IdeApp.Workspace.CurrentSelectedSolution?.FileName.FullPath.ToString(); if (!string.IsNullOrEmpty(solutionPath)) { reply.SetParamDescriptorforKeyword( NSAppleEventDescriptor.DescriptorWithString(solutionPath), keyDirectObject); LoggingService.LogInfo($"{nameof (GetCurrentSelectedSolutionPath)}: replying to AppleEvent {@event} with {solutionPath}"); } }
public MusicPlayer(String _name) { this.name = _name; //プレイリストの取得 String script = string.Format("tell application \"{0}\" to get name of user playlists", this.name); NSAppleEventDescriptor result = Requesttoitunes(script); nint B = result.NumberOfItems; playlist = new String[B]; for (int i = 0; i < playlist.Length; i++) { playlist[i] = result.DescriptorAtIndex(i + 1).StringValue; } }
public void AppleScript_BasicTest() { #pragma warning disable 0219 const string script = @"tell application ""Finder"" end tell"; NSAppleScript s = new NSAppleScript(script); NSDictionary errorInfo; bool success = s.CompileAndReturnError(out errorInfo); Assert.IsTrue(success); Assert.IsNull(errorInfo); Assert.IsTrue(s.Compiled); NSAppleEventDescriptor descriptor = s.ExecuteAndReturnError(out errorInfo); Assert.IsNull(errorInfo); #pragma warning restore 0219 }
private void HandleGetURLEvent(NSAppleEventDescriptor descriptor, NSAppleEventDescriptor replyEvent) { // Breakpoint here, debug normally and *then* call your URL try { var keyDirectObject = "----"; var keyword = (((uint)keyDirectObject[0]) << 24 | ((uint)keyDirectObject[1]) << 16 | ((uint)keyDirectObject[2]) << 8 | ((uint)keyDirectObject[3])); var openinArgs = descriptor.ParamDescriptorForKeyword(keyword).StringValue; ParseOpeningString(openinArgs); } catch { } }
private void HandleGetURLEvent(NSAppleEventDescriptor descriptor, NSAppleEventDescriptor replyEvent) { // stackoverflow.com/questions/1945 // https://forums.xamarin.com/discussion/9774/custom-url-schema-handling var keyDirectObject = "----"; var keyword = (((uint)keyDirectObject[0]) << 24 | ((uint)keyDirectObject[1]) << 16 | ((uint)keyDirectObject[2]) << 8 | ((uint)keyDirectObject[3])); var urlString = descriptor.ParamDescriptorForKeyword(keyword).StringValue; using (var alert = new NSAlert()){ alert.MessageText = urlString; alert.RunSheetModal(null); } }
static void Main(string[] args) { NSApplication.Init(); Logging.Log("iMessage Bridge 1.0"); NSUserDefaults.StandardUserDefaults.RegisterDefaults(NSDictionary.FromFile(NSBundle.MainBundle.PathForResource("DefaultPreferences", "plist"))); // Find out if user is logged into iMessage. NSAppleScript asConnectionStatus = new NSAppleScript("tell application \"Messages\" to get 1st service's connection status whose service type = iMessage"); NSDictionary ei; NSAppleEventDescriptor aed = asConnectionStatus.ExecuteAndReturnError(out ei); if (ei == null) { if (aed.StringValue == "dcon") // iMessage service is disconnected. { NSAlert alert = new NSAlert() { MessageText = "It appears you're not signed in to iMessage.", InformativeText = "The bridge will not work if you are not signed in. Would you like to sign in to iMessage?" }; alert.AddButton("Yes"); alert.AddButton("Not now"); NSRunningApplication.CurrentApplication.Activate(NSApplicationActivationOptions.ActivateIgnoringOtherWindows); if (alert.RunModal() == 1000) // User clicks yes. { Process.Start("/Applications/Messages.app"); } Environment.Exit(1); } } DatabaseStore.Init(); HttpServer.Start(); StreamServer.Start(); if (NSUserDefaults.StandardUserDefaults.BoolForKey("DiscoveryMode")) { Discovery.Register(); } NSApplication app = NSApplication.SharedApplication; app.Delegate = new AppDelegate(); app.Run(); }
public void HandleGetURLEvent(NSAppleEventDescriptor evt, NSAppleEventDescriptor replyEvt) { NSError error; shouldOpenInitialFile = evt.NumberOfItems == 0; // Received event is a list (1-based) of URL strings for (int i = 1; i <= evt.NumberOfItems; i++) { var innerDesc = evt.DescriptorAtIndex(i); // The next call works fine but is Lion-specific // controller.OpenDocument (new NSUrl (innerDesc.StringValue), i == evt.NumberOfItems, delegate {}); if (!string.IsNullOrEmpty(innerDesc.StringValue)) { NSUrl url = new NSUrl(innerDesc.StringValue); Call_OpenDocument(url, true, out error); } } }
void HandleGetUrlEvent(NSAppleEventDescriptor descriptor, NSAppleEventDescriptor reply) { var openUrlEvent = OpenUrl; if (openUrlEvent == null) { return; } string keyDirectObjectString = "----"; uint keywordDirectObject = (((uint)keyDirectObjectString [0]) << 24 | ((uint)keyDirectObjectString [1]) << 16 | ((uint)keyDirectObjectString [2]) << 8 | ((uint)keyDirectObjectString [3])); string urlString = descriptor.ParamDescriptorForKeyword(keywordDirectObject).ToString(); openUrlEvent(NSApplication.SharedApplication, new OpenUrlEventArgs(urlString)); }
partial void SettingsButtonClick(NSObject sender) { var current = NSApplication.SharedApplication.CurrentEvent; //Checking if the app is in the login items or not var script = "tell application \"System Events\"\n get the name of every login item\n if login item \"Ambar\" exists then\n return true\n else\n return false\n end if\n end tell"; NSAppleScript appleScript = new NSAppleScript(script); var errors = new NSDictionary(); NSAppleEventDescriptor result = appleScript.ExecuteAndReturnError(out errors); isLoginItem = result.BooleanValue; if (!isLoginItem) { launch.State = NSCellStateValue.Off; } else if (isLoginItem) { launch.State = NSCellStateValue.On; } NSMenu.PopUpContextMenu(settingsMenu, current, sender as NSView); }
public override void ViewDidMoveToWindow() { base.ViewDidMoveToWindow(); LyricsTextView.Value = currentDelegate.controller.TrackLyrics.message.body.lyrics.lyrics_body; TrackName.StringValue = currentDelegate.controller.Track; ArtistName.StringValue = currentDelegate.controller.Artist; if (currentDelegate.controller.TrackLyrics.message.body.lyrics.@explicit == 1) { ExplicitTag.Hidden = false; } else { ExplicitTag.Hidden = true; } if (currentDelegate.controller.App == "iTunes") { PlayerIcon.Image = new NSImage("icon_itunes.pdf"); script = new NSAppleScript(File.ReadAllText("Scripts/GetAlbumArtiTunes.txt")); result = script.ExecuteAndReturnError(out errors); NSImage cover = new NSImage(result.Data); AlbumArtView.Image = cover; ThumbnailView.Image = cover; } else { PlayerIcon.Image = new NSImage("icon_spotify.pdf"); script = new NSAppleScript(File.ReadAllText("Scripts/GetAlbumArtSpotify.txt")); result = script.ExecuteAndReturnError(out errors); NSUrl artworkurl = new NSUrl(result.StringValue); NSImage cover = new NSImage(artworkurl); AlbumArtView.Image = cover; ThumbnailView.Image = cover; } containerHeight = (float)LyricsTextView.Bounds.Height; }
private void FetchLyrics() { stateMachine.StartLoading(); if (Reachability.IsNetworkAvailable()) { script = new NSAppleScript(File.ReadAllText("Scripts/GetCurrentSong.txt")); result = script.ExecuteAndReturnError(out errors); //The NumberofItems property is being used to handle different use cases. Check GetCurrentSong.txt in Scripts folder to know more if (result.NumberOfItems == 3) { artist = result.DescriptorAtIndex(1).StringValue; track = result.DescriptorAtIndex(2).StringValue; app = result.DescriptorAtIndex(3).StringValue; var lyrics = lyricsHelper.GetLyrics(track, artist, (response, artist_name, share_url) => { tracklyrics = JsonConvert.DeserializeObject <TrackLyrics.RootObject>(response); if (tracklyrics.message.body.lyrics.instrumental == 0) { track_share_url = share_url; stateMachine.ShowContent(); } else { stateMachine.ShowEmpty(); } }); } else if (result.NumberOfItems == 0) { switch (result.StringValue) { //Transitioning to error state of state machine and calling the corresponding delegate method //These delegates method are being used so that one view can be reused for various error cases. case "1": stateMachine.ShowError(); NothingPlayingFound?.Invoke(this, null); break; case "2": stateMachine.ShowError(); NoMusicAppRunningFound?.Invoke(this, null); break; case "3": stateMachine.ShowError(); MultiPlayingFound?.Invoke(this, null); break; } } else { stateMachine.ShowError(); LyricsNotFoundOccurred?.Invoke(this, null); } } else { stateMachine.ShowError(); NetworkErrorOccurred?.Invoke(this, null); } }
public void UrlHandleEvent(NSAppleEventDescriptor evt, NSAppleEventDescriptor replyEvt) { Native.UrlHandleEvent(evt, replyEvt); }
internal virtual void HandleGetURLEvent(NSAppleEventDescriptor ae, NSAppleEventDescriptor aeReply) { string url = ae.ParamDescriptorForKeyword(AEKeyword.DirectObject).StringValue; TryOpenFiles(new string[] { url }, Msg.WM_OPEN_URLS); }
//前の曲に移動 public void NextTrack() { String script = string.Format("tell application \"{0}\" to next track", this.name); NSAppleEventDescriptor result = Requesttoitunes(script); }
public virtual bool OpenUrls(NSUrl[] urls, string bundleIdentifier, NSWorkspaceLaunchOptions options, NSAppleEventDescriptor descriptor) { return(_OpenUrls(urls, bundleIdentifier, options, descriptor, null)); }
public virtual bool OpenUrls(NSUrl[] urls, string bundleIdentifier, NSWorkspaceLaunchOptions options, NSAppleEventDescriptor descriptor, string[] identifiers) { // Ignore the passed in argument, because if you pass it in we will crash on cleanup. return(_OpenUrls(urls, bundleIdentifier, options, descriptor, null)); }
public void HandleGetURLEvent (NSAppleEventDescriptor evt, NSAppleEventDescriptor replyEvt) { NSError error; shouldOpenInitialFile = evt.NumberOfItems == 0; // Received event is a list (1-based) of URL strings for (int i = 1; i <= evt.NumberOfItems; i++) { var innerDesc = evt.DescriptorAtIndex (i); // The next call works fine but is Lion-specific //controller.OpenDocument (new NSUrl (innerDesc.StringValue), i == evt.NumberOfItems, delegate {}); Call_OpenDocument (new NSUrl (innerDesc.StringValue), i == evt.NumberOfItems, out error); } }
public void UrlHandleEvent (NSAppleEventDescriptor evt, NSAppleEventDescriptor replyEvt) { var url = evt.ParamDescriptorForKeyword (AppleEventParameters.DirectObject).StringValue; SimpleAuth.NativeSafariAuthenticator.ResumeAuth (url); }
//現在の曲を再生、停止する関数 public void PlayPause() { String script = string.Format("tell application \"{0}\" to playpause", this.name); NSAppleEventDescriptor result = Requesttoitunes(script); }
void HandleGetUrlEvent(NSAppleEventDescriptor descriptor, NSAppleEventDescriptor reply) { var openUrlEvent = OpenUrl; if (openUrlEvent == null) return; string keyDirectObjectString = "----"; uint keywordDirectObject = (((uint)keyDirectObjectString [0]) << 24 | ((uint)keyDirectObjectString [1]) << 16 | ((uint)keyDirectObjectString [2]) << 8 | ((uint)keyDirectObjectString [3])); string urlString = descriptor.ParamDescriptorForKeyword (keywordDirectObject).ToString (); openUrlEvent (NSApplication.SharedApplication, new OpenUrlEventArgs (urlString)); }
//指定されたプレイリストを再生する関数 public void Playplaylist(String _player_name, String _music_title) { String script = "tell application \"" + _player_name + "\" to play playlist \"" + _music_title + "\""; NSAppleEventDescriptor result = Requesttoitunes(script); }
public void UrlHandleEvent(NSAppleEventDescriptor evt, NSAppleEventDescriptor replyEvt) { var url = evt.ParamDescriptorForKeyword(AppleEventParameters.DirectObject).StringValue; SimpleAuth.NativeSafariAuthenticator.ResumeAuth(url); }