StrokesPlus.net
Welcome Guest! To enable all features please Login or Register.

Notification

Icon
Error

Options
Go to last post Go to first unread
Rob  
#1 Posted : Friday, April 26, 2019 11:15:02 AM(UTC)
Rob

Rank: Administration

Reputation:

Groups: Translators, Members, Administrators
Joined: 1/11/2018(UTC)
Posts: 684
United States
Location: Tampa, FL

Thanks: 13 times
Was thanked: 155 time(s) in 134 post(s)
This script will check to see if Spotify is already running, and if so activate it, otherwise open Spotify.
Code:
var spotifyWindows = sp.AllApplications().Where(a => a.Process.MainModule.FileName.includes("Spotify.exe"));
if(spotifyWindows) {
    var mainSpotifyWindow = sp.WindowFromHandle(spotifyWindows.First().Process.MainWindowHandle);
    mainSpotifyWindow.Activate();
} else {
    // Open spotify (obviously change the path accordingly)
    sp.RunProgram('Spotify.exe', '', 'open', '', true, false, false); 
}

Edited by user Friday, April 26, 2019 2:34:34 PM(UTC)  | Reason: Not specified

thanks 1 user thanked Rob for this useful post.
ScalableMan on 6/13/2019(UTC)
Rob  
#2 Posted : Sunday, April 28, 2019 11:35:19 AM(UTC)
Rob

Rank: Administration

Reputation:

Groups: Translators, Members, Administrators
Joined: 1/11/2018(UTC)
Posts: 684
United States
Location: Tampa, FL

Thanks: 13 times
Was thanked: 155 time(s) in 134 post(s)
This does a similar thing, but for OneNote (Office16 version, change exe name accordingly). This is a little faster since it doesn't access .Process, but assumes only one app/window is open that ends with " - OneNote"
Code:
var appWindows = sp.WindowsFromTitleRegex('.* - OneNote$');
if(appWindows && appWindows.Count() > 0) {
    appWindows.First().Activate();
} else {
    // Open app
    var ret = sp.RunProgram('ONENOTE.EXE', '', 'open', '', true, false, false); 
}

Edited by user Sunday, April 28, 2019 11:36:35 AM(UTC)  | Reason: Not specified

Users browsing this topic
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.