K
Koen Vervloesem
--Apple-Mail-5--332282667
Content-Transfer-Encoding: 7bit
Content-Type: text/plain;
charset=US-ASCII;
format=flowed
Hi,
Today I made a simple tool for MacOS X. I heavily use the "open"
command in MacOS X: When I'm working in the Terminal and I want to open
a PDF file in Acrobat Reader, I just have to type "open file.pdf" and
it opens quickly in Acrobat Reader. But when I know the url of a PDF
file on the net, an I type "open http://blabla.org/file.pdf", it opens
an empty Safari window before opening the PDF file in Acrobat Reader.
That's because "open" opens all files in a http url with the standard
browser.
That gave me the idea to make a configurable script that can open local
and remote files like the command "open", but you can specify in a
configuration file which remote files the script has to open with the
default browser. Regularly, you want html files (and php and some
others) to be opened by your browser directly, and all others (pdf, ps,
tar.gz) downloaded by the unclose script and opened by their standard
application. So you don't get an empty browser window with Safari.
I have included the source code of unclose.rb. All arguments to the
script are opened as files or urls. You can configure unclose.rb in a
file .uncloserc in your home directory. This file can contain e.g.:
download_dir ~/Desktop/Download
no_download html
no_download php
This says all downloaded files will be downloaded in de directory
Desktop/Download in your home directory, and that remote html and php
files will be viewed directly by your browser and not downloaded by
unclose to be viewed locally by your browser.
I'd like to get some comments. I want to extend unclose to be used with
other operating systems if e.g. GNU/Linux or MS Windows have a similar
command as the "open" command. And I will support more protocols, like
ftp and scp. After that, I will package it in RAA.
Regards,
Koen Vervloesem
--
"Men have a gene which enables them to answer any question, no matter
how complex or important, with Mmm."
--Apple-Mail-5--332282667
Content-Disposition: attachment;
filename=unclose.rb
Content-Transfer-Encoding: 7bit
Content-Type: application/octet-stream;
x-unix-mode=0644;
name="unclose.rb"
# unclose 0.1 alpha
# A helper script for the MacOS X "open" command.
#
# (c) 2003 Koen Vervloesem
# mailto: (e-mail address removed)
require 'uri'
require 'net/http'
# The class Encloser has one public method: open.
# With this method, one can open a remote or local file.
class Uncloser
# Open <document>.
def Uncloser.open(document)
doc_uri = uri(document)
if doc_uri != nil and download?(doc_uri)
document = to_download_dir(document)
download(doc_uri, document)
end
openlocal(document)
end
private
# Download <uri> and save it in file with name <filename>
def Uncloser.download(uri, filename)
Net::HTTP.start(uri.host, uri.port) {|http|
response = http.get(uri.path)
f = File.new(filename, "w")
f.syswrite(response.body)
f.close
}
end
# Do we have to download <uri>?
def Uncloser.download?(uri)
filename = uri.path
if filename.include?(".")
extension = filename.split(".").last
puts extension
UncloseConfig.download?(extension)
else
true
end
end
# Open the local file <document> with the system's open command.
def Uncloser.openlocal(document)
system(UncloseConfig.open_command, document)
end
# Give the full path of the downloaded file <document>.
def Uncloser.to_download_dir(document)
UncloseConfig.download_dir + "/" + File.basename(URI.parse(document).path)
end
# Give a supported uri object of <document>.
# Now only the http scheme is supported.
def Uncloser.uri(document)
uri = URI.parse(document)
if uri.scheme == 'http'
uri
else
nil
end
end
end
# This class reads the configuration of Unclose in its configuration file.
class UncloseConfig
CONFIG_FILE = ENV["HOME"] + "/.uncloserc"
# Do we have to download a file with extension <extension>?
def UncloseConfig.download?(extension)
ignore =[]
if FileTest.exists?(CONFIG_FILE)
IO.foreach(CONFIG_FILE) { |line|
puts line
if line =~ /^no_download\s+(\S+)/
ignore << $1.upcase
end
}
end
!ignore.include?(extension.upcase)
end
# What is the download directory?
def UncloseConfig.download_dir
dir = "."
if FileTest.exists?(CONFIG_FILE)
IO.foreach(CONFIG_FILE) { |line|
if line =~ /^download_dir\s+(\S+)/ and FileTest.directory?(File.expand_path($1))
dir = File.expand_path($1)
end
}
end
dir
end
# What is the open command of our operating system?
def UncloseConfig.open_command
command = "open"
if FileTest.exists?(CONFIG_FILE)
IO.foreach(CONFIG_FILE) { |line|
if line =~ /^open_command\s+(\S+)/ and FileTest.executable?($1)
dir = $1
end
}
end
command
end
end
# Open all arguments with Uncloser.
ARGV.each {|x| Uncloser.open(x)}
--Apple-Mail-5--332282667--
Content-Transfer-Encoding: 7bit
Content-Type: text/plain;
charset=US-ASCII;
format=flowed
Hi,
Today I made a simple tool for MacOS X. I heavily use the "open"
command in MacOS X: When I'm working in the Terminal and I want to open
a PDF file in Acrobat Reader, I just have to type "open file.pdf" and
it opens quickly in Acrobat Reader. But when I know the url of a PDF
file on the net, an I type "open http://blabla.org/file.pdf", it opens
an empty Safari window before opening the PDF file in Acrobat Reader.
That's because "open" opens all files in a http url with the standard
browser.
That gave me the idea to make a configurable script that can open local
and remote files like the command "open", but you can specify in a
configuration file which remote files the script has to open with the
default browser. Regularly, you want html files (and php and some
others) to be opened by your browser directly, and all others (pdf, ps,
tar.gz) downloaded by the unclose script and opened by their standard
application. So you don't get an empty browser window with Safari.
I have included the source code of unclose.rb. All arguments to the
script are opened as files or urls. You can configure unclose.rb in a
file .uncloserc in your home directory. This file can contain e.g.:
download_dir ~/Desktop/Download
no_download html
no_download php
This says all downloaded files will be downloaded in de directory
Desktop/Download in your home directory, and that remote html and php
files will be viewed directly by your browser and not downloaded by
unclose to be viewed locally by your browser.
I'd like to get some comments. I want to extend unclose to be used with
other operating systems if e.g. GNU/Linux or MS Windows have a similar
command as the "open" command. And I will support more protocols, like
ftp and scp. After that, I will package it in RAA.
Regards,
Koen Vervloesem
--
"Men have a gene which enables them to answer any question, no matter
how complex or important, with Mmm."
--Apple-Mail-5--332282667
Content-Disposition: attachment;
filename=unclose.rb
Content-Transfer-Encoding: 7bit
Content-Type: application/octet-stream;
x-unix-mode=0644;
name="unclose.rb"
# unclose 0.1 alpha
# A helper script for the MacOS X "open" command.
#
# (c) 2003 Koen Vervloesem
# mailto: (e-mail address removed)
require 'uri'
require 'net/http'
# The class Encloser has one public method: open.
# With this method, one can open a remote or local file.
class Uncloser
# Open <document>.
def Uncloser.open(document)
doc_uri = uri(document)
if doc_uri != nil and download?(doc_uri)
document = to_download_dir(document)
download(doc_uri, document)
end
openlocal(document)
end
private
# Download <uri> and save it in file with name <filename>
def Uncloser.download(uri, filename)
Net::HTTP.start(uri.host, uri.port) {|http|
response = http.get(uri.path)
f = File.new(filename, "w")
f.syswrite(response.body)
f.close
}
end
# Do we have to download <uri>?
def Uncloser.download?(uri)
filename = uri.path
if filename.include?(".")
extension = filename.split(".").last
puts extension
UncloseConfig.download?(extension)
else
true
end
end
# Open the local file <document> with the system's open command.
def Uncloser.openlocal(document)
system(UncloseConfig.open_command, document)
end
# Give the full path of the downloaded file <document>.
def Uncloser.to_download_dir(document)
UncloseConfig.download_dir + "/" + File.basename(URI.parse(document).path)
end
# Give a supported uri object of <document>.
# Now only the http scheme is supported.
def Uncloser.uri(document)
uri = URI.parse(document)
if uri.scheme == 'http'
uri
else
nil
end
end
end
# This class reads the configuration of Unclose in its configuration file.
class UncloseConfig
CONFIG_FILE = ENV["HOME"] + "/.uncloserc"
# Do we have to download a file with extension <extension>?
def UncloseConfig.download?(extension)
ignore =[]
if FileTest.exists?(CONFIG_FILE)
IO.foreach(CONFIG_FILE) { |line|
puts line
if line =~ /^no_download\s+(\S+)/
ignore << $1.upcase
end
}
end
!ignore.include?(extension.upcase)
end
# What is the download directory?
def UncloseConfig.download_dir
dir = "."
if FileTest.exists?(CONFIG_FILE)
IO.foreach(CONFIG_FILE) { |line|
if line =~ /^download_dir\s+(\S+)/ and FileTest.directory?(File.expand_path($1))
dir = File.expand_path($1)
end
}
end
dir
end
# What is the open command of our operating system?
def UncloseConfig.open_command
command = "open"
if FileTest.exists?(CONFIG_FILE)
IO.foreach(CONFIG_FILE) { |line|
if line =~ /^open_command\s+(\S+)/ and FileTest.executable?($1)
dir = $1
end
}
end
command
end
end
# Open all arguments with Uncloser.
ARGV.each {|x| Uncloser.open(x)}
--Apple-Mail-5--332282667--