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

Notification

Icon
Error

Options
Go to last post Go to first unread
berlihingen  
#1 Posted : Tuesday, January 5, 2021 12:49:09 PM(UTC)
berlihingen

Rank: Member

Reputation:

Groups: Approved
Joined: 11/10/2020(UTC)
Posts: 18

Was thanked: 1 time(s) in 1 post(s)
Happy New Year everyone!
I gave up on running a particular program with arguments. I have a few gestures without immediate visible effect so I want my system to say that the command executed. For now, I wrote a batch file and use it as the last step of action:
Code:
@echo off
start "" nircmd speak text "Closed"

but surely there must be a more direct way. All my attempts to run those commands directly from the SP only triggered errors either by SP or by nircmd.
P.S. Not a problem at all, just for the sake of elegance :)
Rob  
#2 Posted : Tuesday, January 5, 2021 2:29:06 PM(UTC)
Rob

Rank: Administration

Reputation:

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

Thanks: 18 times
Was thanked: 195 time(s) in 170 post(s)
What is the full path to nircmd on your system?

e.g. c:\nircmd\nircmd.exe (or whatever it is)
Rob  
#3 Posted : Tuesday, January 5, 2021 2:34:20 PM(UTC)
Rob

Rank: Administration

Reputation:

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

Thanks: 18 times
Was thanked: 195 time(s) in 170 post(s)
Also, if the speech library loads for you (I had someone in Russia or something where speech failed to load), you can do this in your script:
Code:
var synth = new speech.System.Speech.Synthesis.SpeechSynthesizer();  
synth.SetOutputToDefaultAudioDevice(); 
//synth.SelectVoiceByHints(speech.System.Speech.Synthesis.VoiceGender.Male); //Male voice
synth.SelectVoiceByHints(speech.System.Speech.Synthesis.VoiceGender.Female);  //Female voice
synth.Volume = 25; //0 - 100
synth.Rate = 0;  // -10 (slow) -  10 (fast)
synth.Speak(action.ActionName); //Speaks the name of the action
synth.Dispose();

Or you could put that in your Global Actions > Settings > After Action (choose Custom) and it will speak for all actions.

Note that Applications can also use the global after action, or their own. By default I think it's set to None.

Edited by user Tuesday, January 5, 2021 3:07:04 PM(UTC)  | Reason: Not specified

berlihingen  
#4 Posted : Wednesday, January 6, 2021 12:49:51 AM(UTC)
berlihingen

Rank: Member

Reputation:

Groups: Approved
Joined: 11/10/2020(UTC)
Posts: 18

Was thanked: 1 time(s) in 1 post(s)
Originally Posted by: Rob Go to Quoted Post
What is the full path to nircmd on your system?

e.g. c:\nircmd\nircmd.exe (or whatever it is)


C:\Windows\nircmd.exe
berlihingen  
#5 Posted : Wednesday, January 6, 2021 12:57:53 AM(UTC)
berlihingen

Rank: Member

Reputation:

Groups: Approved
Joined: 11/10/2020(UTC)
Posts: 18

Was thanked: 1 time(s) in 1 post(s)
Originally Posted by: Rob Go to Quoted Post
Also, if the speech library loads for you (I had someone in Russia or something where speech failed to load), you can do this in your script:
Code:
var synth = new speech.System.Speech.Synthesis.SpeechSynthesizer();  
synth.SetOutputToDefaultAudioDevice(); 
//synth.SelectVoiceByHints(speech.System.Speech.Synthesis.VoiceGender.Male); //Male voice
synth.SelectVoiceByHints(speech.System.Speech.Synthesis.VoiceGender.Female);  //Female voice
synth.Volume = 25; //0 - 100
synth.Rate = 0;  // -10 (slow) -  10 (fast)
synth.Speak(action.ActionName); //Speaks the name of the action
synth.Dispose();

.


This works perfectly, can I change ActionName to something else?

Side question: is there any difference in functionality/stability if I use for let's say "Copy" command Step Send HotKey CTRL+C versus Script sp.SendKeys("^c"); ?

Edited by user Wednesday, January 6, 2021 1:31:39 AM(UTC)  | Reason: Not specified

Rob  
#6 Posted : Wednesday, January 6, 2021 4:23:40 AM(UTC)
Rob

Rank: Administration

Reputation:

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

Thanks: 18 times
Was thanked: 195 time(s) in 170 post(s)
Yes, you can change it to any string, like synth.Speak("Closed") - action.ActionName is just a string variable.

There is not much difference in the Step versus Script, but Steps don't use the script engine pool and may be technically slightly more efficient.

Though I haven't run any benchmarks.

Edited by user Wednesday, January 6, 2021 4:25:08 AM(UTC)  | Reason: Not specified

Rob  
#7 Posted : Wednesday, January 6, 2021 4:53:49 AM(UTC)
Rob

Rank: Administration

Reputation:

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

Thanks: 18 times
Was thanked: 195 time(s) in 170 post(s)
And this works for me to use Nircmd:
Code:
sp.RunProgram("C:\\Windows\\nircmd.exe", "speak text \"Closed\"", "open", "none", false, true, false);

Note that with some of the parameters above, I'm telling it to not create a window - so don't reuse this exactly if you're looking to run a program with command line parameters that you actually want to see :)

You'll notice a few things which might explain the errors you were having.

The path must have special characters escaped - \ is the escape character, so you have to escape the escape by using \\ (translates to a single \ ).
You can also see this in action in the command argument "speak text \"Closed\"".
Since " is used to define the beginning and end of a string, you can't have a " inside a string or it will end the string, leaving the rest of the characters which follow being treated as script. So \" escapes the quote, telling the compiler to treat this " as part of the string.

There are several escapes, such as:
- \n (new line)
- \t (tab)
- \\ (\)
- \" (")

You can also use template literal strings via the backtick character so you don't have to escape the quotes (`speak text "Closed"`):
Code:
sp.RunProgram("C:\\Utilities\\Nircmd\\nircmd.exe", `speak text "Closed"`, "open", "none", false, true, false);

Note that the path to the exe would still need the backslashes escaped even if you used backticks as template literals still need to support some escapes, though only:
- \\ (\)
- \$ ($)
- \` (`)

Template literals also allow you to use string interpolation, which is why the $ sign needs to be escaped, but it may not be something you use:
Code:
var name = "Rob";
sp.MessageBox(`Hi, my name is ${name}`, "Greetings!");


This is all JavaScript, so you can research anything in abundance on the internet.
berlihingen  
#8 Posted : Wednesday, January 6, 2021 5:08:04 AM(UTC)
berlihingen

Rank: Member

Reputation:

Groups: Approved
Joined: 11/10/2020(UTC)
Posts: 18

Was thanked: 1 time(s) in 1 post(s)
That was my guess: I was lost somewhere in syntax. Well, now everything working. Thanks!

One more Q: I have both Hotkey and Script for clipboard actions; I believe it was so from very installation (though not sure). In this case what is SP priority, and wouldn't better to disable one of?

And another one: what wold be sp.SendKeys(" "); for the hotkey LMENU+LWIN+C
Rob  
#9 Posted : Wednesday, January 6, 2021 6:07:08 AM(UTC)
Rob

Rank: Administration

Reputation:

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

Thanks: 18 times
Was thanked: 195 time(s) in 170 post(s)
Quote:
I have both Hotkey and Script for clipboard actions; I believe it was so from very installation (though not sure). In this case what is SP priority, and wouldn't better to disable one of?

I'm not following you here, do you mean Hotkey via Steps and the Script code as well in the same action?
If so, S+ uses whichever tab is selected for the action - Steps or Script - so it doesn't really matter, other than a slightly smaller settings file.

Quote:
And another one: what wold be sp.SendKeys(" "); for the hotkey LMENU+LWIN+C

To be honest, I recommend the other functions for sending complex hotkeys such as that. The easiest way to get the script snippet is to click the Insert Hotkey button in the Script tab and press the key combination you want, then click OK. That will put the script in the script editor for you, which you can then cut/paste somewhere else if needed:
Code:
sp.SendModifiedVKeys([vk.LMENU,vk.LWIN], [vk.VK_C]);

Edited by user Wednesday, January 6, 2021 6:08:46 AM(UTC)  | Reason: Not specified

Rob  
#10 Posted : Wednesday, January 6, 2021 6:17:47 AM(UTC)
Rob

Rank: Administration

Reputation:

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

Thanks: 18 times
Was thanked: 195 time(s) in 170 post(s)
Also, via the Send Hot Key Step, you can click in the text box and press the key combination you want instead of using scripts.
berlihingen  
#11 Posted : Wednesday, January 6, 2021 6:20:32 AM(UTC)
berlihingen

Rank: Member

Reputation:

Groups: Approved
Joined: 11/10/2020(UTC)
Posts: 18

Was thanked: 1 time(s) in 1 post(s)
Quote:
do you mean Hotkey via Steps and the Script code as well in the same action?

Yes
Quote:
If so, S+ uses whichever tab is selected for the action - Steps or Script

Wow, good to know!
Quote:
to click the Insert Hotkey button

Shame on me – forgot it is here...

Thanks again! I'm learning little by little :)
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.