Skip to content
Browse files

simplify reveal code os x

  • Loading branch information...
1 parent 6ca2c19 commit 44fc5fe0a21c209e88fd437249c208d8225a3d7d @rdp committed Nov 24, 2011
Showing with 5 additions and 137 deletions.
  1. +1 −0 drive_info.rb
  2. +2 −2 spec/swing_helpers.spec.rb
  3. +2 −1 swing_helpers.rb
  4. +0 −134 vendor/reveal
View
1 drive_info.rb
@@ -22,6 +22,7 @@
class DriveInfo
def self.md5sum_disk(dir)
+ dir = '"' + dir + '"'
if OS.mac?
command = "#{__DIR__}/vendor/mac_dvdid/bin/dvdid #{dir}"
else
View
4 spec/swing_helpers.spec.rb
@@ -42,12 +42,12 @@ module SwingHelpers
it "should reveal a file" do
FileUtils.touch "a b"
SwingHelpers.show_in_explorer "a b"
- Dir.mkdir "a dir"
+ Dir.mkdir "a dir" unless File.exist?('a dir')
SwingHelpers.show_in_explorer "a dir"
end
it "should reveal a url" do
- SwingHelper.show_url_in_browser "www.google.com"
+ SwingHelpers.open_url_to_view_it_non_blocking "http://www.google.com"
end
end
View
3 swing_helpers.rb
@@ -122,6 +122,7 @@ def bring_to_front # kludgey...but said to work for swing apps
end
def self.open_url_to_view_it_non_blocking url
+ raise unless url =~ /^http/i
if OS.windows?
system("start #{url.gsub('&', '^&')}") # LODO would launchy help/work here with the full url?
else
@@ -240,7 +241,7 @@ def self.show_in_explorer filename_or_path
rescue => why_does_this_happen_ignore_this_exception_it_probably_actually_succeeded
end
elsif OS.mac?
- c = File.expand_path(__DIR__ + "/vendor/reveal") + " \"" + File.expand_path(filename_or_path) + "\""
+ c = "open -R " + "\"" + File.expand_path(filename_or_path) + "\""
puts c
system c
else
View
134 vendor/reveal
@@ -1,134 +0,0 @@
-#!/bin/zsh
-
-commandName=${0##*/}
-
-usage() {
- if [[ $1 != '' ]] ; then echo 1>&2 "\n$1" ; fi
- echo 1>&2 "
-Usage: $commandName
- $commandName [ -l ] [ -v ] item ...
-
-Tells the Finder to reveal the current directory or a list of the given items.
-The -l argument tells the Finder to set the last window it opens to list view.
-The -v argument causes the AppleScript to be echoed to stderr.
-
-In the multiple-arguments case, the Finder will open one window that cantains
-all of the items and select them all. Maybe someday it will do that even if
-the items are not all in the same folder (using list view and expanded subfolders).
-
-Author: Dave@Yost.com 2002-12-09, 2004-06-05, 2006-07-07
-Version 1.2
-"
- exit 2
-}
-
-zparseopts -D -K - -help=argHelp l=argList v=argVerbose
-
-if [[ $#argHelp != 0 ]] ; then
- usage
-fi
-
-case $1 in
--*) usage "Unknown option: $1"
- ;;
-esac
-
-#-----------------------------------------
-
-# unix path -> old-style Mac path for AppleScript
-colonize() {
- sed 's,.*,"&",
- s,/,\&,g
- s,:,/,g
- s,^"&Volumes&,",
- s,^"&.*,& of startup disk,' \
- | sed 's,&,:,g' \
- | tr -d '\012'
-}
-
-# Reveal unix paths in the Finder
-reveal() {
- if [ $# = 0 ] ; then
- args=( . )
- else
- args=( $* )
- fi
-
- itemList=
- for x in $args
- do
- case "$x" in
- /*) item="$x" ;;
- .) item="`/bin/pwd`" ;;
- *) item="`/bin/pwd`/$x" ;;
- esac
-
- # All /x/../ -> /
- previtem=
- while [ "$previtem" != "$item" ]
- do
- previtem="$item"
- item=`echo "$item" | sed 's,[^/]*/\.\./,,'`
- done
-
- if [ $item = / ] ; then
- itemColonized="startup disk"
- else
- itemColonized="item $(echo -n $item | colonize)"
- fi
-
- # Add it to the list
- if [ "$itemList" = "" ] ; then
- itemList="Â
- $itemColonized"
- else
- itemList="$itemList, Â
- $itemColonized"
- fi
- done
-
- script='
- tell application "Finder"
- reveal { '$itemList' Â
- }'
- if [ "$#argList" != 0 ] ; then
- script="$script
- get every Finder window whose index is 1
- set the current view of item 1 of the result to list view"
- fi
- script="$script"'
- activate
- end tell'
- if [[ $#argVerbose != 0 ]] ; then
- echo 1>&2 "[osascript -e '$script
-']"
- fi
- osascript -e "$script"
-}
-
-test() {
- # If there are any mounted volumes, try the first one.
- mountedVolume=`mount | grep Volumes | sed -n '1s,^[^ ]* on \(.*\) (*[^(]*,\1,p'`
- if [ "$mountedVolume" != "" ] ; then
- $commandName "$mountedVolume"
- fi
- cd /Library
- $commandName
- $commandName "/"
- $commandName Preferences
- $commandName "/Applications/QuickTime Player.app" \
- "/Applications/Utilities/Java/../../System Preferences.app"
-}
-
-case $# in
-0) reveal "`/bin/pwd`"
- ;;
-*) case "$1" in
- --test)
- test
- ;;
- *) $commandName $*
- ;;
- esac
- ;;
-esac

0 comments on commit 44fc5fe

Please sign in to comment.
Something went wrong with that request. Please try again.