rgcr / m-cli Goto Github PK
View Code? Open in Web Editor NEW Swiss Army Knife for macOS
License: MIT License
Swiss Army Knife for macOS
License: MIT License
Found this Apple OS X Command Line documentation, which could be a gold-mine of potential additions to this project.
$ mdfind
Usage: mdfind [-live] [-count] [-onlyin directory] [-name fileName | -s smartFolderName | query]
list the files matching the query
query can be an expression or a sequence of words
-attr <attr> Fetches the value of the specified attribute
-count Query only reports matching items count
-onlyin <dir> Search only within given directory
-live Query should stay active
-name <name> Search on file name only
-reprint Reprint results on live update
-s <name> Show contents of smart folder <name>
-0 Use NUL (``\0'') as a path separator, for use with xargs -0.
example: mdfind image
example: mdfind -onlyin ~ image
example: mdfind -name stdlib.h
example: mdfind "kMDItemAuthor == '*MyFavoriteAuthor*'"
example: mdfind -live MyFavoriteAuthor
$ softwareupdate
usage: softwareupdate <cmd> [<args> ...]
** Catalog Management:
--set-catalog <URL> Set the new catalog URL (requires privileges)
--clear-catalog Clear the catalog URL back to defaults (requires privileges)
** Manage Updates:
-l | --list List all appropriate update labels (options: --no-scan)
-d | --download Download Only
-e | --cancel-download Cancel a download
-i | --install Install
<label> ... specific updates
-a | --all All appropriate updates
-r | --recommended Only recommended updates
--background Trigger a background scan and update operation
--ignore <label> ... Ignore specific updates
--reset-ignored Clear all ignored updates
** Other Tools:
--suspend-background Suspend background operations from occurring temporarily (use --duration to specify duration to suspend in seconds)
--duration <duration>) Optional duration in seconds to suspend background operations (defaults to 5*60 seconds)
--dump-state Log the internal state of the SU daemon to /var/log/install.log
--evaluate-products Evaluate a list of product keys specified by the --products option
** Options:
--no-scan Do not scan when listing or installing updates (use available updates previously scanned)
--products A comma-separated (no spaces) list of product keys to operate on.
--force Force an operation to complete. Use with --background to trigger a background scan regardless of "Automatically check" pref
--verbose Enable verbose output
--help Print this help
$ tmutil
Usage: tmutil version
Usage: tmutil enable
Usage: tmutil disable
Usage: tmutil startbackup [-a | --auto] [-b | --block] [-r | --rotation] [-d | --destination dest_id]
Usage: tmutil stopbackup
Usage: tmutil enablelocal
Usage: tmutil disablelocal
Usage: tmutil snapshot
Usage: tmutil delete snapshot_path ...
Usage: tmutil restore [-v] src ... dst
Usage: tmutil compare [-@acdefghlmnstuEX] [-D depth] [-I name]
tmutil compare [-@acdefghlmnstuEX] [-D depth] [-I name] snapshot_path
tmutil compare [-@acdefghlmnstuEUX] [-D depth] [-I name] path1 path2
Usage: tmutil setdestination [-a] mount_point
tmutil setdestination [-ap] afp://user[:pass]@host/share
Usage: tmutil removedestination destination_id
Usage: tmutil destinationinfo [-X]
Usage: tmutil addexclusion [-p|-v] item ...
Usage: tmutil removeexclusion [-p|-v] item ...
Usage: tmutil isexcluded item ...
Usage: tmutil inheritbackup machine_directory
tmutil inheritbackup sparse_bundle
Usage: tmutil associatedisk [-a] mount_point volume_backup_directory
Usage: tmutil latestbackup
Usage: tmutil listbackups
Usage: tmutil machinedirectory
Usage: tmutil calculatedrift machine_directory
Usage: tmutil uniquesize path ...
Usage: tmutil verifychecksums path ...
Not sure how difficult this would be.
Can't seem to find a built in way of doing it.
If I type m <tab>
, in zsh, I'm getting the following:
_m:2: unknown file attribute: \n
_m:2: unknown file attribute: \n
Any ideas? Some googling brings up something about zsh arrays not being the same as bash arrays but I'm not sure that's the problem here. Sorry for not giving more information but I'm not what would be helpful – so please let me know. Thanks very much!
Just curious how everyone felt about using AppleScript within the CLI to accomplish certain things. Seeing as this is a macOS only project, I don't see the harm. Thoughts?
Any chance to install from homebrew?
I got the following error~
➜ ~ m vpn start 8CB2849B-5EC3-4F80-88E5-02E41CD9BA7A 'user' 'mypass'
scutil: unrecognized option `--pasword'
usage: scutil
interactive access to the dynamic store.
or: scutil --prefs [preference-file]
interactive access to the [raw] stored preferences.
or: scutil [-W] -r nodename
or: scutil [-W] -r address
or: scutil [-W] -r local-address remote-address
check reachability of node, address, or address pair (-W to "watch").
or: scutil -w dynamic-store-key [ -t timeout ]
-w wait for presense of dynamic store key
-t time to wait for key
or: scutil --get pref
or: scutil --set pref [newval]
or: scutil --get filename path key
pref display (or set) the specified preference. Valid preferences
include:
ComputerName, LocalHostName, HostName
newval New preference value to be set. If not specified,
the new value will be read from standard input.
It'd be really nice to have this available on Homebrew and they like for there to be a git tag of a stable release to point most people at (with the option to install directly from the latest master
). Any chance we could have a stable released tagged? ❤️
When typing m network ls
, I get a list of all interfaces and their Mac addresses.
Expected behavior: seeing the current IP addresses as well. That would be really useful to have for troubleshooting purposes.
Not sure if this is easy/hard/impossible, but I'd like a scripted way to toggle the "Show Wi-Fi status in menu bar" setting from the Network preferences screen. I think this uses the defaults
system and updates something like NSStatusItem Visible com.apple.menuextra.airport" = 1;
but I don't know the proper incantation to simulate the Preferences Pane behavior via command line.
"com.apple.systemuiserver" = {
"NSStatusItem Visible Siri" = 0;
"NSStatusItem Visible com.apple.menuextra.airport" = 1;
"NSStatusItem Visible com.apple.menuextra.battery" = 1;
"NSStatusItem Visible com.apple.menuextra.bluetooth" = 1;
"NSStatusItem Visible com.apple.menuextra.clock" = 1;
"NSStatusItem Visible com.apple.menuextra.textinput" = 1;
"__NSEnableTSMDocumentWindowLevel" = 1;
"last-messagetrace-stamp" = "497807700.002411";
menuExtras = (
"/System/Library/CoreServices/Menu Extras/Clock.menu",
"/System/Library/CoreServices/Menu Extras/TextInput.menu",
"/System/Library/CoreServices/Menu Extras/Bluetooth.menu",
"/System/Library/CoreServices/Menu Extras/Battery.menu",
"/System/Library/CoreServices/Menu Extras/AirPort.menu"
);
};
Whenever I want to change my wallpaper I would assume to navigate to the directory where the desired image file is located and then run m wallpaper ./image.jpg
. However, when the command is run the dock disappears for a moment (restarting the Finder I guess) and the wallpaper is changed to the default wallpaper of macOS. The image which was mentioned in the command is not used.
I have not found any issue related to this problem so there are two possibilities: I am not using the command correctly or there is an issue in the project nobody before me has found. Also there could be a bug that only shows up on my machine.
The new m finder desktop
subcommand takes as arguments enable
and disable
, lowercase only. This is in contrast to m finder showhiddenfiles
and m finder showextensions
, which both take yes
and no
case-insensitively. Additionally, the bash completion will only suggest YES
and NO
. This should be unified so that m finder desktop
takes yes
and no
case-insensitively. Alternatively, all three commands could be extended to take yes
, no
, enable
, and disable
case-insensitively.
Additionally, both showhiddenfiles
and showextensions
are clear in what they mean: showhiddenfiles
means the finder will show hidden files and showextensions
means that the finder will show file extensions. desktop
is vague. It should probably be renamed to showdesktop
.
when i set the Locking settings of Near Lock
: Sleep, m screensaver askforpassword NO
doesn't work;
when i set the Locking settings of Near Lock
: ScreenSaver, m screensaver askforpassword YES
doesn't work;
$ m trash clean
chflags: /Users/contra/.Trash/*: No such file or directory
Hi, thanks for the hard work into this project!
I am trying to install the project into my home folder, the documentation says i can specify a path with INSTALL_DIR
but that function does not appear to be working. The following is an example of me trying to install m-cli into ~/.m-cli
but is instead being installed into /usr/local/m-cli
. I am not sure if the documentation is wrong or if the function is broken. See example below.
c in ~
› INSTALL_DIR=~/.m-cli curl -fsSL https://raw.githubusercontent.com/rgcr/m-cli/master/install.sh | sh
Downloading m-cli from git to /usr/local
Cloning into '/usr/local/m-cli'...
remote: Counting objects: 38, done.
remote: Compressing objects: 100% (36/36), done.
remote: Total 38 (delta 3), reused 21 (delta 1), pack-reused 0
Unpacking objects: 100% (38/38), done.
Checking connectivity... done.
Done!
c in ~
› ls -la ~ | grep m-cli
c in ~
› ls -la /usr/local | grep m-cli
drwxr-xr-x 10 c admin 340 17 Jul 01:30 m-cli
c in ~
›
Thanks again!
The most universal and complete way to set a path variable on OS X (all users, all recent version of OS X, GUI & CLI) is the /etc/paths.d/
directory. Instead of (or in addition to) the recommendation to put "export $PATH..." inside one of the user profiles, the install process can recommend something like sudo echo '/usr/local/m-cli' > /etc/paths.d/m-cli
. Or it can be an automatic part of the install process. There are permission issues (in both cases) to iron out, though.
USER@HOST:~$ m
-bash: m: command not found
macOS 10.11.5, using iTerm2 Build 3.0.4, but same problem in standard macOS Terminal. Ran the installscript multiple times, always says, already installed. But no luck getting it to work.
Any suggestions?
➜ ~ m --update
m-cli Is already installed
Updating m-cli from git
remote: Total 0 (delta 0), reused 0 (delta 0), pack-reused 0
HEAD is now at d0b6f56 Merge 'jfultz-master',we can launch m from a symlink
Done!
➜ ~ m safeboot status
nvram: Error getting variable - 'boot-args': (iokit/common) data was not found
➜ ~
I would like to know if there is interested in a keyboard command.
If there is I can add it
To switch keyboard layouts, (like https://github.com/Lutzifer/keyboardSwitcher (this is written in obj-c))
To set custom mappings for mapping keys
And to change the general keyboard settings
(ref https://github.com/doodzik/osx_init/blob/master/system_config.sh#L19-L30)
CreateDesktop
defaults to being unset. As such, if it hasn't ever been manually set, running m finder desktop
yields an error:
$ m finder desktop
/usr/local/Cellar/m-cli/0.1.0/plugins/finder: line 70: [: : integer expression expected
Desktop is: enabled
$
The relevant section of the code:
DESKTOP_STATUS_NUM=$(defaults read com.apple.finder CreateDesktop 2>/dev/null)
if [ "$DESKTOP_STATUS_NUM" -eq 0 ] ; then
Running the defaults
command manually:
$ defaults read com.apple.finder CreateDesktop 2>/dev/null
$ defaults read com.apple.finder CreateDesktop # let's check for errors
2016-08-03 12:31:39.782 defaults[90896:5643237]
The domain/default pair of (/Users/elyscape/Library/Preferences/com.apple.finder, CreateDesktop) does not exist
$ # aha
Model Name: MacBook Pro
Model Identifier: MacBookPro11,3
Processor Name: Intel Core i7
Bluetooth Firmware Version: v118 c9121
Doesn't enable hardware using m bluetooth enable
. reports same as disable, which works fine.
Thanks for putting this utility together it is very helpful.
Is it be possible to require the password only once instead of having to re-enter it for certain commands? Or is there a limitation/security concern in enabling that functionality that lead to the current implementation?
As an example:
$: m hostname
Password:
ComputerName: [computername]
Password:
HostName: [hostname]
Password:
...
Enabling bluetooth using m bluetooth enable
does not get it enabled without sending a SIGHUP to blued by doing a sudo killall -HUP blued
like m bluetooth disable
does.
as seen here
When I start VPN I get an error from AppleScript
$ m vpn start <name>
missing value
I'd use scutil --nc start "$1"
instead. Do you want me to file a pull request?
By the way, great projects!
Cheers
Hi Rogelio,
Since this contains basically 97% of the code from Mac CLI, you should reference that your tool is based on my project.
I am okay with you when it comes to reusing the code, but it all comes down to being fair.
If not, all the credit goes to you but the effort of creating the tool for more than 6 months was made by me.
Looking forward your response.
Gabriel
Is this normal?
This project offers now 3 different completion solutions. IMO we should look into removing that repetition.
Does anyone have a suggestion for tackling this problem?
That would really help me understand this package.
Hello,
With m lock
I get an animation before it locks the screen. I also get an animation when after entering my password when unlocking. Is there a way to disable this?
Thank you.
Needs no description.
Adding support for most common screen capture use-cases might be nice.
For example:
screencapture -iW ~/Desktop/screen.jpg
(where i
flag is interactive and W
is Window Selection Mode)screencapture -i ~/Desktop/screen.jpg
screencapture -S ~/Desktop/screen.jpg
I envision the CLI interaction might look something like:
usage: m screencap [ file-name | -w | -f | -r | help ]
Examples:
m screencap # full screencapture of current screen. File saved as ~/Desktop/screen.jpg
m screencap window.png -w # prompt user to select a window to screencapture
m screencap ~/Documents/full.jpg -f # full screencapture of current screen
m screencap rectangle.pdf -r # prompt user to select custom dimensions.
Gotchas:
~/Desktop/screen.png
)Reference: http://guides.macrumors.com/Taking_Screenshots_in_Mac_OS_X
When using the command m vpn start VPNNAME username password
I'm getting the following error:
scutil: unrecognized option
--user username'`
It is apparently the result of quoting the arguments. Submitting a PR to demonstrate the fix..
I really like having to open manual pages by simply typing m bash
or something like it. I really like these utilities but they all start with an m. Is there a way I can change this first 'm' to something else and keep my alias for man pages?
Thank you for any help.
any plans to support connecting to a listed vpn?
great tool
Per this article, it seems that controlling iTunes via Bash is possible.
I haven't tested it and I don't know if the API has changed much for OS X versions released after 2001.
TL;DR
#!/bin/sh
#
####################################
# iTunes Command Line Control v1.0
# written by David Schlosnagle
# created 2001.11.08
####################################
showHelp () {
echo "-----------------------------";
echo "iTunes Command Line Interface";
echo "-----------------------------";
echo "Usage: `basename $0` <option>";
echo;
echo "Options:";
echo " status = Shows iTunes' status, current artist and track.";
echo " play = Start playing iTunes.";
echo " pause = Pause iTunes.";
echo " next = Go to the next track.";
echo " prev = Go to the previous track.";
echo " mute = Mute iTunes' volume.";
echo " unmute = Unmute iTunes' volume.";
echo " vol up = Increase iTunes' volume by 10%";
echo " vol down = Increase iTunes' volume by 10%";
echo " vol # = Set iTunes' volume to # [0-100]";
echo " stop = Stop iTunes.";
echo " quit = Quit iTunes.";
}
if [ $# = 0 ]; then
showHelp;
fi
while [ $# -gt 0 ]; do
arg=$1;
case $arg in
"status" ) state=`osascript -e 'tell application "iTunes" to player state as string'`;
echo "iTunes is currently $state.";
if [ $state = "playing" ]; then
artist=`osascript -e 'tell application "iTunes" to artist of current track as string'`;
track=`osascript -e 'tell application "iTunes" to name of current track as string'`;
echo "Current track $artist: $track";
fi
break ;;
"play" ) echo "Playing iTunes.";
osascript -e 'tell application "iTunes" to play';
break ;;
"pause" ) echo "Pausing iTunes.";
osascript -e 'tell application "iTunes" to pause';
break ;;
"next" ) echo "Going to next track." ;
osascript -e 'tell application "iTunes" to next track';
break ;;
"prev" ) echo "Going to previous track.";
osascript -e 'tell application "iTunes" to previous track';
break ;;
"mute" ) echo "Muting iTunes volume level.";
osascript -e 'tell application "iTunes" to set mute to true';
break ;;
"unmute" ) echo "Unmuting iTunes volume level.";
osascript -e 'tell application "iTunes" to set mute to false';
break ;;
"vol" ) echo "Changing iTunes volume level.";
vol=`osascript -e 'tell application "iTunes" to sound volume as integer'`;
if [ $2 = "up" ]; then
newvol=$(( vol+10 ));
fi
if [ $2 = "down" ]; then
newvol=$(( vol-10 ));
fi
if [ $2 -gt 0 ]; then
newvol=$2;
fi
osascript -e "tell application \"iTunes\" to set sound volume to $newvol";
break ;;
"stop" ) echo "Stopping iTunes.";
osascript -e 'tell application "iTunes" to stop';
break ;;
"quit" ) echo "Quitting iTunes.";
osascript -e 'tell application "iTunes" to quit';
exit 1 ;;
"help" | * ) echo "help:";
showHelp;
break ;;
esac
done
Please add auto-completions for the majestic FISH shell.
Hey, here's the output from the terminal
File "/usr/local/m-cli/plugins/lock", line 10
m lock # lock session"""
^
SyntaxError: Missing parentheses in call to 'print'
Hello,
I just installed this and after running m dir
I get the following:
➜ ~ m dir tree
/usr/local/m-cli/plugins/dir: line 3: /lib/functions.sh: No such file or directory
Everything else seems fine:
➜ ~ m --update
m-cli Is already installed
Updating m-cli from git
m remote: Total 0 (delta 0), reused 0 (delta 0), pack-reused 0
HEAD is now at 516b2eb updating readme
➜ ~ m battery status
Now drawing from 'AC Power'
-InternalBattery-0 100%; charged; 0:00 remaining present: true
Just an idea, but the DNS cache flush operation is different dependent on your version of Mac OS, and it isn't exactly pretty:
From https://support.apple.com/en-gb/HT202516:
10.10.4 and later:
sudo killall -HUP mDNSResponder
10.10 to 10.10.3:
sudo discoveryutil mdnsflushcache
10.9.5 and earlier:
sudo killall -HUP mDNSResponder
10.6 to 10.6.8:
sudo dscacheutil -flushcache
Can not update homebrew installed m-cli, getting message that not a git repository.
I run the command 'm --update' and it shows the following:
> m --update
m-cli is already installed
Updating m-cli from git
fatal: Not a git repository: '/usr/local/Cellar/m-cli/0.1.0/.git'
Failed to fetch changes => https://github.com/rgcr/m-cli.git
Which I would assume that I should use 'brew upgrade m-cli' if I installed it with homebrew. Just thought I would advise on the error message when I try to upgrade via m-cli
It would be great if you could have it output the current active application and window name.
This is a simple feature request. I find that after I begin a script, I realize I would like to use 'm nosleep until' on that process. I can do that with caffeinate by running 'caffeinate -w PID'. I think it would be nice to support that feature in m-cli.
I would be happy to make a pull request with this addition, but I am not sure how best to add the feature. As of now, 'm nosleep until NUMBER' will not sleep for NUMBER seconds. There would need to be a way to specify that the number is a PID. Perhaps, prefixing the number with a + or some other character? Backwards compatibility should not be broken.
Let me know what you think. Like I said, I would be happy to make a pull request with the changes. I really enjoy using this tool and would love to contribute to it!
Hi!
Just recently found this tool and find it very nice. No longer need to remember the weird commands in OSX to configure it is great! Thanks!
Have you considered an option for getting a prompt to type in the password instead of having to have it in the command?
I'm no talking about the admin password but for example when connecting to VPN or wifi.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.