Posted on 02-02-2023 11:56 AM
Any youtube channels or website where I can practice and learn scripting or get practice scripts to run and see how they work.
Thanks
02-02-2023 12:39 PM - edited 02-02-2023 01:00 PM
@acamare5 You'll find lots of scripts posted on Jamf Nation, and this post asking for scripting resources has recommendations for a few sites: https://community.jamf.com/t5/jamf-pro/scripting-resources/td-p/220869 (I'll 2nd the recommendation there for Scripting OS X and the site author has also written a couple of scripting related books you'll find mentioned on the site)
Jamf's own @talkingmoose has an intro to scripting video, and the accompanying article has an extensive list of resources: https://www.jamf.com/blog/just-10-commands-then-keep-learning/
It hasn't been updated since 2014, but Apple's Developer site does have a Shell Scripting Primer: https://developer.apple.com/library/archive/documentation/OpenSource/Conceptual/ShellScripting/Intro...
Posted on 02-02-2023 01:26 PM
@talkingmoose scripting video helped me out a lot. I re-watch it here and there. Easy to follow and very useful.
Posted on 02-02-2023 09:57 PM
Yes, there are several YouTube channels and websites that can help you learn scripting and practice with scripts. Here are a few popular options:
These resources offer interactive tutorials, video lessons, and practice exercises to help you learn scripting and improve your skills. Additionally, you can find a wide range of scripts on websites such as GitHub (github.com) and Stack Overflow (stackoverflow.com) that you can run and modify to better understand how they work.
02-03-2023 05:47 AM - edited 02-03-2023 05:53 AM
Honestly, I have never found any youtube channels for macOS scripting to be very useful. They all go from this is terminal to "now that we are all experts on looping if statement you are ready to go" way too fast. Granted we all learn a bit differently, but I always find it best to have a practical real world goal.
I suggest starting with file manipulation.
From this you can test each command really easy, and then start stringing things together for a script. With it being file related its easy to see the results of what you are doing.
Make a file on your desktop.
touch /Users/{your user name/Desktop/file_name.txt
*do not use ~ for your profile in a script, play with it and figure out why this wont work if run from JAMF.
touch ~/Desktop/File_Name.txt
Move the file from your desktop to documents
mv /Users/{your user name/Desktop}/file_name.txt /Users/{your user name/documents
Make a command to create a file on your desktop, then move it to your documents. Then add when your mac rebooted last to the text document
*Scripts need the 1st line to point to the interpreter, 99% of the time that will be #!/bin/sh. however it can be any interpreter on the Mac.
#!/bin/sh
touch /users/{user name}/desktop/file.txt
mv /users/{user name}/desktop/file.txt /users/{user name}/documents
uptime >> /users/{user name}/documents/file.txt
A script is literally just a text file, the file extension for a shell script is .sh but macOS really does not need the file extension. Use something like Visual Studio code to make your scripts, you want a plain text editor so done use text edit or MS Word. If you got a few bucks to toss around I like Code Runner 2. XCode is really overkill but can also be a text editor for scrips.
To run a script locally open terminal and use sudo sh {path to script}
sudo sh "/Users/desktop/my amazing script.sh"
The last thing I will mention on scripting, terminal sees spaces as new commands. If your file path has spaces in it, quote the file path or or terminate the spaces. The three examples below will all terminate the space between File and Name.
/Users/{user name}/desktop/"file name.txt"
"/Users/{user name}/desktop/file name.txt"
/Users/{user name}/desktop/file\ name.txt
Basically just about all scripting is file manipulation in some way shape or form. Learning the basics is a really good place to start. You want to read or modify a plist, you use defaults read or defaults write but its still just a text file.