Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot use powershell for scripts #1458

Open
ramarivera opened this issue Apr 20, 2024 · 3 comments
Open

Cannot use powershell for scripts #1458

ramarivera opened this issue Apr 20, 2024 · 3 comments

Comments

@ramarivera
Copy link

I have the following simple script

// Name: RecycleDefaultAppPool

import "@johnlindquist/kit";

function configure() {
  $.shell = "powershell.exe";
}

function showNotificationUsingPowershell(message: string) {
  console.log(`Set to ${$.shell}`);

  const script = `Add-Type -AssemblyName System.Windows.Forms
$notifyIcon = New-Object System.Windows.Forms.NotifyIcon
$notifyIcon.Icon = [System.Drawing.SystemIcons]::Information
$notifyIcon.BalloonTipIcon = 'Info'
$notifyIcon.BalloonTipText = '${message}'
$notifyIcon.BalloonTipTitle = 'Notification'
$notifyIcon.Visible = $true
$notifyIcon.ShowBalloonTip(10000)`;

  $`${script}`;
}

configure();

console.log("Recycling DefaultAppPool");
console.log(`Set to ${$.shell}`);

let applicationPoolToRestartName = await arg({
  placeholder: "Name of the application pool to restart?",
  initialChoices: ["DefaultAppPool"],
});

dev();

showNotificationUsingPowershell(`Recycling ${applicationPoolToRestartName}...`);

However when I execute it, it tries to use bash, even tho I told it to use powershell and can see in the dev console that $.shell is set to powershell.

What am I doing wrong? 😢

@ramarivera
Copy link
Author

Now this is fun lol

If I use instead

async function showNotificationUsingPowershell(message: string) {
  const script = `Add-Type -AssemblyName System.Windows.Forms
$notifyIcon = New-Object System.Windows.Forms.NotifyIcon
$notifyIcon.Icon = [System.Drawing.SystemIcons]::Information
$notifyIcon.BalloonTipIcon = 'Info'
$notifyIcon.BalloonTipText = '${message}'
$notifyIcon.BalloonTipTitle = 'Notification'
$notifyIcon.Visible = $true
$notifyIcon.ShowBalloonTip(10000)`;

  const results = await term({
    command: script,
    shell: "powershell.exe",
  });

  console.log("RESULTS", script, results);
}

it does open powershell, but it executes the lines in the inverse order 🙃 e.g. $notifyIcon.ShowBalloonTip(10000) first

@JosXa
Copy link
Contributor

JosXa commented Apr 24, 2024

Try await exec(script, { shell: 'powershell' }) for powershell, and the builtin notify helper for native notifications. It uses https://www.npmjs.com/package/node-notifier under the hood

@ramarivera
Copy link
Author

Yeah the notifications wwere just a random example, because I needed something very bright and loud, akin to a console.log :D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants