Jump to content

Archived

This topic is now archived and is closed to further replies.

Seshan

[Version 1] Basic Open Terminal And Run A Command

Recommended Posts

This should open Spot Light It's uses CMD+Space, but since spot lights command can easily be changed or you can even disable spot light all together it may not work.

What it does:

Blinks once when starting the code

Quits any popup that pops up

Opens spot light

Searches and opens terminal

Pings google (this can be changed to what ever you want it to do

CTRL+C to stop anything running

Quits terminal

Blinks twice when it finishes running.

int ledPin = 11;

void setup() {
  pinMode(ledPin, OUTPUT);
}
void loop() {
  delay(8000);
  //LED blinks when code starts
  digitalWrite(ledPin, HIGH);
  delay (1000);
  digitalWrite(ledPin, LOW);
  // Command key
  Keyboard.set_modifier(MODIFIERKEY_GUI);
  Keyboard.send_now();
  // Command key + Q to quit any pop ups
  Keyboard.set_key1(KEY_Q);
  Keyboard.send_now();
  // releases Q key
  Keyboard.set_key1(0);
  Keyboard.send_now();
  // delay
  delay(500);
  // open spotlight
  Keyboard.set_key1(KEY_SPACE);
  Keyboard.send_now();
  // releases keys
  Keyboard.set_modifier(0);
  Keyboard.set_key1(0);
  Keyboard.send_now();
  // open terminal
  Keyboard.print("terminal.app");
  // delay
  delay(50);
  Keyboard.set_key1(KEY_ENTER);
  Keyboard.send_now();
  Keyboard.set_key1(0);
  Keyboard.send_now();
  // delay for termianl to load
  delay(4000);
  // enters someothing in terminal
  Keyboard.print("ping www.google.ca");
  delay(50);
  Keyboard.set_key1(KEY_ENTER);
  Keyboard.send_now();
  Keyboard.set_key1(0);
  Keyboard.send_now();
  //time for command to run
  delay(9000);
  //stops commands
  Keyboard.set_modifier(MODIFIERKEY_CTRL);
  Keyboard.send_now();
  Keyboard.set_key1(KEY_C);
  Keyboard.send_now();
  Keyboard.set_key1(0);
  Keyboard.set_modifier(0);
  Keyboard.send_now();
  //quits terminal
  Keyboard.set_modifier(MODIFIERKEY_GUI);
  Keyboard.send_now();
  Keyboard.set_key1(KEY_Q);
  Keyboard.send_now();
  Keyboard.set_key1(0);
  Keyboard.send_now();
  delay(200);
  //led blinks twice when code ends
digitalWrite(ledPin, HIGH);
  delay (1000);
  digitalWrite(ledPin, LOW);
  delay (1000);
  digitalWrite(ledPin, HIGH);
  delay (1000);
  digitalWrite(ledPin, LOW);

  delay(900000);
}

Share this post


Link to post
Share on other sites

This way does work and will work on a lot of Mac's, but will encounter some issues.

Example, I just ran it, and instead of running Terminal it ran a program I have called "Terminal Emulator" which will not run the commands, just something to bare in mind.

But cool none the less.

Share this post


Link to post
Share on other sites

Yeah there are to many variables with OS X, when you type just "terminal" into spot light does terminal show up?

Share this post


Link to post
Share on other sites
Yeah there are to many variables with OS X, when you type just "terminal" into spot light does terminal show up?

Yes it does show up, its just not the first option, and this assumes that it will be the first option.

Share this post


Link to post
Share on other sites

Damn, to bad there is no keyboard short cut to open the terminal. Maybe if I tell it to type terminal.app?

Share this post


Link to post
Share on other sites
Damn, to bad there is no keyboard short cut to open the terminal. Maybe if I tell it to type terminal.app?

Yes, that selects it as the first option. :D

Share this post


Link to post
Share on other sites

Sweet, thanks for the help. :D

The code has been changed. :D

Share this post


Link to post
Share on other sites
You could just make it search Terminal.app in spotlight.

Thats what it does...

Share this post


Link to post
Share on other sites

Suggestion: What you type in Terminal should be "somecommand -with -some args && killall Terminal" to kill the terminal once the payload completes. This won't work for constant payloads such as ping, however most payloads will be quick, not something which stays running forever.

Share this post


Link to post
Share on other sites

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...