How to add PowerShell script to the dock on Mac

Hi All,


I wrote a powershell script which works great when I run from the terminal, type pwsh then call the script file. I'm hoping to be able to add the script to the dock and be able to click it and have it open. Is there any way to do that?


Thanks



[Re-Titled by Moderator]

Posted on Feb 28, 2024 1:42 PM

Reply
14 replies

Mar 6, 2024 5:42 AM in response to JCtech2025

Have you enabled the Zsh shell as your default Shell, and configured a ~/.zshrc file in your home directory? Also, note that Automator is a cascade of arguments from one action to another and doesn't know the PATH that you have setup in your Shell dot file.


So launching the PowerShell application and then using a Run Shell Script action won't do a thing for you unless you are passing arguments to the Zsh shell and processing those arguments in a Run Shell Script script. Pretty sure that the Run Shell Script does not offer PowerShell as one of its Shell arguments.


You will likely need to create a HERE document in that Run Shell Script that invokes PowerShell to run the associated HERE code as in this example using Python3 from a Python.org installation:



Since this was coded, the Shell: options now include this /usr/local/bin/python3 and the HERE syntax is no longer needed. You would not need to have a preceding action to launch PowerShell when used in this manner provided that PowerShell supports this form of invocation.



Mar 4, 2024 4:46 PM in response to JCtech2025

Microsoft provided a release of Powershell for the Mac. Apple's developers have absolutely nothing to do with that product, or creating any convenience for its usage.


If Microsoft can compile their own powershell scripts into an Apple compatible .app, then it will be accessible from the Dock, or anywhere one can double-click it in the Finder. Otherwise, it will need to be run from the Terminal command-line like any other scriptable language script.

Feb 29, 2024 12:27 PM in response to Barney-15E

To both comments above. I have not done any work with exporting as an app or AppleScript. Been working with macOS for about a year now. I found a way to install Powershell in MACOS and then wrote the code in visual studio code. I have been building a tool that can run on the desktop in both macOS and Windows and give users the same results regardless of what os they are in. I'm just at the point in Mac where I have to launch from terminal every time, so trying to get it to the launchpad then dock, thus reaching out to this community. Thanks again.

Mar 4, 2024 12:10 PM in response to JCtech2025

Power Shell is a Microsoft product and your source of help. If you posted in the Apple Developers Forum, anyone responding to your post there would most likely not be writing in Powershell and would refer you to Microsoft. Powershell is Microsoft's idea of an alien invasion on macOS…


Apple's supported Shell is Zsh and legacy Bash 3.2.57. That is what the rest of use when writing shell scripts as there is adequate documentation and support.

Mar 4, 2024 2:17 PM in response to VikingOSX

I understand all that. I posted here cause, I was able to install Powershell in macOS, I was also able to write the script in vs code in macOS and run in terminal as a live script. Really was just hoping to be able to load Powershell in macOS and point to the script as a shortcut to load, it's super useful, I thought others would fine the same. I figured it would take Apple dev's to make powershell work on macOS, I just didn't know where to start. I know it's a stretch in the dark. Also trying not to reinvent the wheel since the script does work.

Mar 5, 2024 4:14 PM in response to VikingOSX

Ok update to this thread. When I go to automator and under "launch applications", select Powershell by itself and hit run Powershell loads. From there if I add "Run Shell Script" and put the full path to my script it throws "zsh permission denied". So now it looks like a permissions issue? Not sure why I would get permissions denied this way? Thanks all.

Mar 6, 2024 11:17 AM in response to VikingOSX

Is zsh shell terminal? I am not familiar with a zshrc file. Sorry, It was mentioned in the article I found that got me started on this whole thing. I think part of my issue is my lack of experience with these tools. When I use automator, the workflow starts and I see a gear icon on top of the screen that its running. Issue is I see the Powershell prompt and that's it. Also think part of the issue is my script runs live per se. Terminal at this point is my only option. Here is the article that I started with: https://cloudlearning365.com/?p=1607.

Mar 6, 2024 11:45 AM in response to JCtech2025

If you installed PowerShell using homebrew package manager, it will be installed in either /opt/homebrew/bin/pwsh (arm64) or /usr/local/bin/pwsh (Intel) locations. If you installed via a direct download from Microsoft, then it will be in /usr/local/bin/pwsh.


Microsoft indicates that they have not finished testing PowerShell on macOS Sonoma (14.*) and testing to date is only complete for Big Sur (11.*).


When you launch the Terminal application, enter this command at the prompt:


echo $SHELL


It will be either /bin/bash, or /bin/zsh.


I recommend you get comfortable with the Microsoft PowerShell documentation for Mac and that will be your principal source of ongoing support.

Mar 6, 2024 11:55 AM in response to VikingOSX

Thanks for that information. I installed it using homebrew package, I update powershell using brew upgrade. I ran that command and it says /bin/zsh. As it does show testing isn't done on Sonoma I am kind of running in circles at this point. I'll reference the article you mentioned. This isn't a requirement or anything to run on Mac, I just thought it would be helpful to have the same script run on both platforms.

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

How to add PowerShell script to the dock on Mac

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple Account.