最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

How can I run a Powershell script from a shortcut on macOS and have it display the text output from the script - Stack Overflow

programmeradmin1浏览0评论

I have a powershell script that I'm trying to run from a shortcut on macOS (as in the Shortcuts app/widget, not the Dock). I have the mac version of powershell installed and the script runs fine if I call it directly from the terminal. I can't seem to call powershell scripts at all from a shortcut, but I found that I can create a .sh script that calls the .ps1 script, using the full path to the powershell library, I can get the script to run.

The problem is that the script has output text that I need to be able to see. This method displays the initial text that is output as the script starts, but additional text that is output as the script is running never gets displayed.

Another solution would be to have the shortcut open the terminal window with the required text commands, but I can't figure out how to do that either.

I have a powershell script that I'm trying to run from a shortcut on macOS (as in the Shortcuts app/widget, not the Dock). I have the mac version of powershell installed and the script runs fine if I call it directly from the terminal. I can't seem to call powershell scripts at all from a shortcut, but I found that I can create a .sh script that calls the .ps1 script, using the full path to the powershell library, I can get the script to run.

The problem is that the script has output text that I need to be able to see. This method displays the initial text that is output as the script starts, but additional text that is output as the script is running never gets displayed.

Another solution would be to have the shortcut open the terminal window with the required text commands, but I can't figure out how to do that either.

Share edited Feb 10 at 17:55 mklement0 440k68 gold badges702 silver badges918 bronze badges asked Feb 10 at 17:46 HypersapienHypersapien 6232 gold badges9 silver badges24 bronze badges 1
  • Read following : learn.microsoft/en-us/powershell/scripting/developer/cmdlet/… – jdweng Commented Feb 10 at 18:45
Add a comment  | 

1 Answer 1

Reset to default 0

Figured out the answer. I just needed to run a bash script in the shortcut with this code

osascript -e 'tell app "Terminal"
    do script "cd /foldername\n./filename.ps1"
end tell'

And I can string as many commands together as I want with newlines

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论