Posts Tagged ‘osascript’

Screen capture a remote desktop into the remote clipboard

Friday, January 6th, 2012

I’m working a bit with Apple Remote Desktop now and I’m having trouble taking screen captures. It seems easy to take a screen capture that ends up as a file on or in the clipboard of the client side. But I’d rather be completely immersed in the remote computer, so ideally when I hit CMD+SHIFT+3 I’d get a screen shot the size and resolution of my remote desktop saved to the remote’s clipboard.

Here’s what I’m doing for now. I prepare my app that I want to screen capture then I switch to terminal and issue


echo "tell application \"skinning\" to activate" | osascript - && screencapture -c

This switches to my app and takes a screen capture into the clipboard.

Build and run current xcode project from command line

Friday, June 18th, 2010

I edit my source code via the command line using vim. Then I need to go into xcode and push build/run to debug the code I’m working on. I’d rather just issue a command from vim. Here’s a cheap way to build and run via and applescript which can then be called by vim.
Save the following applescript as xcode_build_and_launch.scpt


tell application "Xcode"
  activate
  set targetProject to project of active project document
	
  if (build targetProject) starts with "Build succeeded" then
    launch targetProject
  end if
end tell

Then from vim you can issue:


:!osascript path/to/xcode_build_and_launch.scpt

This will activate xcode and build the current project, and if that succeeds then it will launch the current executable target.

Note: I stripped the above out of code from a question on stackoverflow. Apparently this will not work for iPhone simulator projects.

Update: I like to call it from vim with the bash time command and then I have an idea of how long the compile took.


:!time osascript path/to/xcode_build_and_launch.scpt

Retrieve current user’s full name, Mac OS X

Saturday, December 5th, 2009

osascript is a command that allows you to execute applescript via the command line and in script. Here’s a short command that retrieves the current users full name.


osascript -e "long user name of (system info)"

Anyone know how to do this in pure bash/unix tools?

Update: Gmail Notifier corrupted my osascript so now I have to send the bogus errors to /dev/null like this:


osascript -e "long user name of (system info)" 2>/dev/null

Update:
Here’s another way I found the long user name:


system_profiler  | grep "User Name:" | sed "s/^      User Name: \([^(]*\) (.*/\1/g"

Update: On linux consider using this:


getent passwd $USER | cut -d ":" -f 5