timetraveller1992

Hide/Show Desktop App for Mavericks Using Java

Jun 16th, 2014
281
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.39 KB | None | 0 0
  1. package com.imoz;
  2.  
  3. import java.io.IOException;
  4.  
  5. import org.jnativehook.GlobalScreen;
  6. import org.jnativehook.NativeHookException;
  7. import org.jnativehook.mouse.NativeMouseEvent;
  8. import org.jnativehook.mouse.NativeMouseInputListener;
  9.  
  10. public class MouseHide implements NativeMouseInputListener {
  11.     boolean hidden = false;
  12.         public void nativeMouseClicked(NativeMouseEvent e) {
  13.                 if(e.getClickCount() == 2)
  14.                 {
  15.                     Process p;
  16.                     if(hidden)
  17.                         hidden = false;
  18.                     else
  19.                         hidden = true;
  20.                     try {
  21.                         p = Runtime.getRuntime().exec("defaults write com.apple.finder CreateDesktop -bool " + hidden);
  22.                         p.waitFor();
  23.                         p = Runtime.getRuntime().exec("killall Finder");
  24.                         p.waitFor();
  25.                     } catch (IOException e1) {
  26.                         // TODO Auto-generated catch block
  27.                         e1.printStackTrace();
  28.                     } catch (InterruptedException e1) {
  29.                         // TODO Auto-generated catch block
  30.                         e1.printStackTrace();
  31.                     }
  32.                      
  33.                 }
  34.         }
  35.  
  36.         public void nativeMousePressed(NativeMouseEvent e) {
  37.                 //System.out.println("Mosue Pressed: " + e.getButton());
  38.         }
  39.  
  40.         public void nativeMouseReleased(NativeMouseEvent e) {
  41.                 //System.out.println("Mosue Released: " + e.getButton());
  42.         }
  43.  
  44.         public void nativeMouseMoved(NativeMouseEvent e) {
  45.                 //System.out.println("Mosue Moved: " + e.getX() + ", " + e.getY());
  46.         }
  47.  
  48.         public void nativeMouseDragged(NativeMouseEvent e) {
  49.                 //System.out.println("Mosue Dragged: " + e.getX() + ", " + e.getY());
  50.         }
  51.  
  52.         public static void main(String[] args) {
  53.                 try {
  54.                         GlobalScreen.registerNativeHook();
  55.                 }
  56.                 catch (NativeHookException ex) {
  57.                         System.err.println("There was a problem registering the native hook.");
  58.                         System.err.println(ex.getMessage());
  59.  
  60.                         System.exit(1);
  61.                 }
  62.  
  63.                 //Construct the example object.
  64.                 MouseHide example = new MouseHide();
  65.  
  66.                 //Add the appropriate listeners for the example object.
  67.                 GlobalScreen.getInstance().addNativeMouseListener(example);
  68.                 GlobalScreen.getInstance().addNativeMouseMotionListener(example);
  69.         }
  70. }
Advertisement
Add Comment
Please, Sign In to add comment