Skip to main content

Posts

Showing posts with the label Terminal

How to get current loggedin user on Mac via script

I won't waste time wiring details. This works as of today, but what will Apple do in future, only God knows.  🤓  It's always suggested to run the command without variable to ensure it work, but you probably know that.  CurrUser=$(echo "show State:/Users/ConsoleUser" | scutil | awk '/Name :/ && ! /loginwindow/ { print $3 }')

How To: Bash Script to add AD User & Group to SSH in Mac

Today morning I got a request from Green IT folks to enabled SSH on all the Macs that we have in Enterprise. Currently SSH is not enabled on clients and not even the Admins are allowed to do so. As it was against InfoSec policy of the client, they needed a solution that ensures SSH is not enabled for anyone except couple of Service Accounts that does background job. So what I proposed was simple, to create a Security Group in AD and add all Service Accounts to that Group and grant SSH access to that group. Now, no one else will be able to access via SSH except the members of this group. So here is what I wrote for them. In this script Joulix is the AD account and HM Admin Mac SSH is the AD group that needs SSH access.:   #!/bin/bash   # To add the User / Group to be able to do ssh. # Created by Laeeq Humam | 10.10.2014 | for HCL # Wrote for Green IT via Cisco Joulix. UN="Joulix" MACSSHGROUP="Admin Mac SSH" # Will use this group and user probably once or twice. Varia...

How To: Sleep, Restart & Shut Down using Terminal

I will make this a quick post with three options of  shutdown  command. There are different command for this purpose but  shutdown  is cool to remember. In order to shutdown, type the following command: sudo shutdown -h now On enter it will begin the shutdown process. It is a rather severe shutdown process. It will not tell you to save documents if they are open. You can replace the word ‘now’ with a time in the 24 hour format. To restart use the following command: sudo shutdown -r now To put your Mac to sleep use the following: sudo shutdown -s now You can do more by entering time in 24hrs format. Do a  man shutdown  to learn more.

To Disable quarantine pop up after downloading an application

When you download an application from internet, it gives a prompt to open or go to the website once the downloading is complete. Following this post you can get rid of annoying prompt. Before I start I would rather recommend that if you are new to Mac don’t disable it unless you are well versed with the behavior of Mac Operating system and its functionality. If you are smart enough to manage, then lets move ahead. All you have to do is type the following command on terminal screen. defaults write com.apple.LaunchServices LSQuarantine -bool NO This command stops the quarantine message that you get after downloading is complete. Activation and deactivation of this feature is almost same. All you have to do is change the last section of this command from ‘NO’ to ‘YES’, as mentioned below: defaults write com.apple.LaunchServices LSQuarantine -bool YES I have tested this on two iMacs, please let me know if you face any issue is executing it. Tweet me on: @MacMaste...

How to make Terminal transparent?

Simple way to give a new transparent look to your Terminal Some of us guys might be working on Terminal a lot and might have been boring seeing the same dark black screen. This is a very simple way to give a transparent look to your Terminal window. They call it a hack, but I call it a cool trendy method and is quite useful. First of all you have to enable the tab bar, this can be done by going to View > Show Tab Bar . This usually enables the feature to have more than one tab opened simultaneously. Once you enable the tab bar, you can select the tab at the top of the Terminal window and slightly drag it. This usually moves a tab around, however in the process it makes it invisible. This might need some practice and soon you will be perfect in moving the window in such a way that it will go invisible. If you want modify Terminal even more there is plenty of preferences go to Terminal > Preferences > Settings, here you can change how Terminal looks and behaves.

TURN YOUR MAC ON AUTOMATICALLY (Using Command Line)

If you want to set your Mac so that it turns ON exactly on the time you want, you can do that I used this command syntax: pmset repeat wakeorpoweron MTWRF 00:00:00 Let me simplify the command so that you can understand it. pmset is the command, wakeorpoweron is to tell your Mac to turn it ON if it is OFF or to wake up if it is sleeping. MTWRF are the weekdays where R represents thursday, I know you are smart enough to understand the reason and  00:00:00 is the time you want your Mac is to be back in action. Now, if you want to cancel this schedule, then type the following command:  pmset repeat cancel Though, this is not a big help as it can also be done from energy saving options in your Mac, but there is limit of setting only couple of schedules.  Using command line you can set as many rules as you want. This is what we call being a step ahead of the crowd. In coming posts we will discuss more about pmset command and its versatility.

CONVERTING DMG TO ISO AND ISO TO DMG

Ever happened that you had got an application from a widows user in an ISO format and your machine needs DMG file type. This and vice-versa is possible by using command utility included in Mac OS X called hdiutil . Simply launch the Terminal and use the commands below, replacing the path and image file with your own. Convert a DMG file to ISO format hdiutil convert /path/imagefile.dmg -format UDTO -o /path/convertedimage.iso Convert an ISO file to DMG format hdiutil convert /path/imagefile.iso -format UDRW -o /path/convertedimage.dmg This method is specially beneficial if you have a CD/DVD burner on.

MAKING A FILE/FOLDER INVISIBLE

How to hide a file/folder using Terminal This is one of the greatest technique that I ever came across, I had to share my Mac in office and was curious about hiding confidential data. This was when I started exploring and finally came up with this solution. These commands are to be typed in Terminal. To make a file or folder invisible in Mac OS X Finder setfile -a V testfile.txt Here is goes, the file or folder is no longer visible via the Finder GUI, though it will be by Terminal. Your files are still there and you can find them via the command line and will show with an ls command. If you want your files and folders to be visible again, use this command: To make a file or folder visible again in Mac OS X Finder setfile -a v testfile.txt Now the file/folder will be visible again to the Finder, cool isn't it? Please Note: setfile is a command line utility included in Apple’s Developer Tools, which is a highly recommended optional install included on any Mac OS X install...

CHANGING THE CREATE DATE OF A FILE

Cheating your buddies: How to change create date on a file. Using this awesome trick you can change the create date of a file and show it to you boss as per requirement. Good idea to save your job. It is not just used to change it to a time in past, you can also change it to post creation date if you need it. Here is the syntax that needs to be entered: touch -t 20090101050202 /location/of/file/filename.png Its really simple, we are using the touch command which is really useful and is designed to change file access and modification times. The next part of it is the number, this is the date of the file written in reverse order. 20090101050202 = YYYYMMDDhhmmss, year month day hour minute second. You can omit the seconds section, you really don’t need it. Once as you hit return and everything is done correctly the file access time will have change to what you have feeded.

CHAGING THE SKIN/COLOUR OF TERMINAL

How to change colour of Terminal window I really was not aware of this function within Terminal, unless I read this article few months back. If you use Terminal very often, you might be bored of its monotonous black and green colour. Using this tipyou can spruce Terminal window up so it looks a bit cooler you can very easily, and only takes a couple of clicks, along with this there are mutiple options to really drill down and change and fine tune the colour settings. Here are the steps to follow in order to change the Terminal skin/colour: Go to Terminal > Preference > Settings . On the left coloumn there are multiple options from where you can chose color combination of your choice. Clicking on each option will enable you to see the default settings. If you are lost somewhere, you can then click Default to set is as the default to load and from next time onwards it will open Terminal in default skin.

HOW TO CHANGE WELCOME MESSAGE IN TERMINAL

Changing welcome message in Terminal When you launch Terminal you get the borong black screen with the date and time of your last login. In this post I will mention the steps to change the welcome message in Terminal. This step includes using a sudo command so you will have to be extra careful. 1. Firstly type cd /etc this will change the file path to the etc, i.e. a hidden folder, on your computer. Once done, type sudo pico motd . Now the system will ask you to type in your user password to get it to work. 2. Next step is to type in your message. Once you have finished typing your message, press ctrl+X , to bring up the exit window. On this screen you need to press Y which will save changes and then keep the default file name of motd by pressing Enter . 3. That's done. All you had to do is follow these two steps and your Terminal will welcome you with a customised message of your choice.

CLEARING DNS CACHE

How to clear DNS from Mac OS X Every time when you open a web page its DNS gets stored in cache of the computer. If you want to know what is DNS, read this topic to clear the concept. When these DNS cache become old, in some of the cases they start creating problem. The idea is to delete DNS cache saved in the system. The command has to typed in Terminal, for Leopard it has to be: dscacheutil -flushcache If you still have Tiger running on your Mac, then type the following: lookupd -flushcache After running this command, cache will be clear and it may take a bit longer to open web pages. It is not recommended to constantly flush your cache, once a month or once every two months would be good enough.

CLOSING TERMINAL WITHOUT CONFIRMATION

Getting rid of confirmation prompt in Terminal while closing Sometimes when you close an application, you get a confirmation prompt if you really want to close it. We rarely close the window accidentally and if there is nothing to save in the application then this prompt is irritating, though not useless for novices. So if you find it irritating, here is an option for you to close this down so that it will not bother you next time when you close it. All you have to do is follow the below mentioned steps: i. Once Terminal is launched, go to Preferences > Settings > Shell. ii. Here you will find multiple options. iii. The one you have to work on is at the bottom under “Prompt Before Closing”. iv. Turn it to never and this will stop the warning/prompt every time.