Will this work on Mac OS?
-
Hey at all!
A first release of my plugin comes closer and closer, but I have no possibilities to check my code on Mac OS... To avoid very basic problems, I would like to ask you: What do you think? Will this code work?
` fileContent = "Java -jar " + File.dirname(FILE) + "\Model2GCode.jar"
fileName = File.dirname(FILE) + "\Model2GCode."
fileName << "command" if (RUBY_PLATFORM.downcase.include?("darwin")) # Mac OS
fileName << "bat" if (RUBY_PLATFORM.downcase.include?("mswin")) # Windowsfile = File.new(fileName, "w")
file.write(fileContent)
file.closeUI.openURL(File.dirname(FILE) + "\Model2GCode.bat") if (RUBY_PLATFORM.downcase.include?("mswin")) # Windows
UI.openURL(File.dirname(FILE) + "\Model2GCode.command") if (RUBY_PLATFORM.downcase.include?("darwin")) # Mac OS`@Thom: You wrote a nice post, at which you explained, at which code parts one has to be careful because of the differences between Win / Mac. Could you please give me a link to this post? I could not find it anymore
Thanks for your help!
-
@aerilius said:
File.join("folder1", "folder2", "filename")
Oh yes, you are right! This is the next point on my list. However, thanks a lot for the hint!!!
OSX = ( Object::RUBY_PLATFORM =~ /(darwin)/i ? true : false ) unless defined?(OSX) WIN = ( not OSX ) unless defined?(WIN)
This looks very smart! Thanks!!
-
Hi,
first, backslashes are a relict from when Windows did not need to support nested folder structures. File path delimiters differ between operating systems and because of that Ruby has super cool abstracted methods to deal with that, ie.
[File.join](http://www.ruby-doc.org/core-1.8.6/File.html#method-c-join)("folder1", "folder2", "filename")
So it is best to clean up a file path immediately when you receive it (from the UI etc.):
` # This resolves relative paths and symbolic links and makes sure all delimiters will be later the same.
path = File.expand_path( File.dirname(FILE) )This joins the paths.
filename = File.join(path, "Model2GCode.")`
In order to avoid repetition, you can define operating system constants once:
` OSX = ( Object::RUBY_PLATFORM =~ /(darwin)/i ? true : false ) unless defined?(OSX)
WIN = ( not OSX ) unless defined?(WIN)if WIN
do_something
elsif OSX
do_something_else
end`For the rest, I have to leave the field for actual OS X users.
-
hi,
you may need a java version test, as mac no longer ships with it pre-installed, it does however recomend installing as part of the start-up sequence.
so, from ruby console
java_version=(`java -version 2>&1`).split("\n")[0].to_s.split[-1] "1.6.0_37"
john
Advertisement