powershell external script

Ask and answer questions related to any type of OSA scripting.
Post Reply
Message
Author
amz4u2nv
Posts: 115
Joined: Mon Sep 03, 2012 3:12 am

powershell external script

#1 Post by amz4u2nv » Thu Jun 19, 2014 9:50 am

Hi Guys,
I need some help, I'm running an external powershell script to run a command -
in osa i have this -

Write-Output "IN SWITCH OUTSIDE SOEAKERS"
cd c:\Users\Andy\Documents
Set-ExecutionPolicy Unrestricted

.\outsidespeakers.ps1



and in outside speakers.ps1
i have this -

Write-Output "IN SWITCH OUTSIDE SOEAKERS"

cd c:\Users\Amit\Documents\SoundSwitch\bin

Write-Output "TEST1"
$program = ".\SetDefaultAudioEndpoint.exe"

Write-Output "TEST2"
$test = Invoke-Command -ScriptBlock { & $program -pOutsideSpeakers }

Write-Output "TEST3"
Write-Output "TESTING $test"

The variable $test would provide some output i.e. switched audio to OutsideSpeakers but the $test variable is empty...
Running each line on the console works correctly, what am i missing.

amz4u2nv
Posts: 115
Joined: Mon Sep 03, 2012 3:12 am

Re: powershell external script

#2 Post by amz4u2nv » Thu Jun 19, 2014 12:56 pm

I've managed to get it to execute ...using od "Execute Command"
however the command switches the audio from one to another, and this takes about a second or two... how can i delay the script from outputting voice command before actuallyign setting the correct sound output.

Automate
Posts: 1691
Joined: Sat Dec 11, 2010 1:44 pm
Location: US

Re: powershell external script

#3 Post by Automate » Thu Jun 19, 2014 1:30 pm


amz4u2nv
Posts: 115
Joined: Mon Sep 03, 2012 3:12 am

Re: powershell external script

#4 Post by amz4u2nv » Fri Jun 20, 2014 2:32 pm

hi,
Start-Sleep -Second 10 used this but it seems to pause the whole script.
i cant get to delay between external call and speech output.
any ideas.

Automate
Posts: 1691
Joined: Sat Dec 11, 2010 1:44 pm
Location: US

Re: powershell external script

#5 Post by Automate » Fri Jun 20, 2014 3:09 pm

Can you post the script you tried?

amz4u2nv
Posts: 115
Joined: Mon Sep 03, 2012 3:12 am

Re: powershell external script

#6 Post by amz4u2nv » Sat Jun 21, 2014 1:15 am

show-osa -name "SpeakingOutside"

invoke-osascript -name "SwitchSoundSpeakers" -nested "true"
invoke-osascript -name "uppervolume"
Start-Sleep -Second 10

$speak_var = get-osa -name "SpeakingOutside"
$speakValue = $speak_var.properties["SayText"].value

invoke-osa -name "Speech" -Method "Say" -parameter1 $speakValue

amz4u2nv
Posts: 115
Joined: Mon Sep 03, 2012 3:12 am

Re: powershell external script

#7 Post by amz4u2nv » Sat Jun 21, 2014 1:17 am

switchsoundspeaker script below

Write-Output "IN SWITCH OUTSIDE SOEAKER"
invoke-osa -name "SERVICE-Amit-PC" -Method "Execute Command" -parameter1 "c:\Users\Amit\Documents\SoundSwitch\bin\SetDefaultAudioEndpoint.exe" -parameter2 "-pOutsideSpeakers"

Vaughn
Site Admin
Posts: 1432
Joined: Thu May 13, 2010 2:17 pm

Re: powershell external script

#8 Post by Vaughn » Sat Jun 21, 2014 5:50 am

"Speaker" is misspelled, just incase it is that easy =) Otherwise, I haven't used PS, so I can't help much.


Vaughn

amz4u2nv
Posts: 115
Joined: Mon Sep 03, 2012 3:12 am

Re: powershell external script

#9 Post by amz4u2nv » Sun Jun 22, 2014 11:02 pm

Nah that's jus output to log text. For some reason it's doing the external execution at the same time as running the rest of the script. Think it might be a bug in osa.
As way around this I got php to call one switch speaker script first and then the second script After 2 seconds. It's a bit hacky as sometimes it could take more than 2 secs.

Post Reply