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 5:15:02 PM(UTC)
Rob

Rank: Administration

Reputation:

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

Thanks: 28 times
Was thanked: 416 time(s) in 354 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 8:34:34 PM(UTC)  | Reason: Not specified

thanks 3 users thanked Rob for this useful post.
ScalableMan on 6/13/2019(UTC), Luis Cisneros on 1/5/2021(UTC), Matija on 6/17/2021(UTC)
Rob  
#2 Posted : Sunday, April 28, 2019 5:35:19 PM(UTC)
Rob

Rank: Administration

Reputation:

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

Thanks: 28 times
Was thanked: 416 time(s) in 354 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 5:36:35 PM(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.