Since as the program folder are differents between Windows and Mac, i wrote the code below.
app = File.read(@path)
if app.empty?
app = UI.openpanel("Pick app")
File.open(@path, "w"){|f|
f.puts "#{app}"
}
end
If the file is empty, everything works fine but if the file is not empty, the app is launched. I would like just read your content to insert into (batch / command) script.
if RUBY_PLATFORM !~ /darwin/i
# WIN
path = UI.openpanel("Pick program","","Executable Files|*.bat;*.cmd;*.com;*.exe;*.ps1;||")
# nil if user cancelled, otherwise a path string
return if path.nil?
# run the app
UI.openURL(path)
else
# OSX
path = UI.openpanel("Pick app","*.app")
# nil if user cancelled, otherwise a path string
return if path.nil?
# run the app
%x{path}
end
I am not sure about the Mac. One of the mac guys can weigh in.
Sorry Dan. I tried to summarize because my english isn’t very good.
I need a file .txt with a program path inside, like “C:\program path\blender.exe”. This path can be different on each computer. Mac or PC.
The first time, the user pick the Blender executable with UI.openpanel and creates a .txt to prevent the user repeat the task.
After this path.txt created, i need to read the content and to create a batch file in Temp folder with the content “C:\program path\blender.exe” -b -P “C:\path\to\file.py” and a VBS for a silent work.
Python file, VBS and Batch in Temp folder is fine, has already been created.
The first time, the whole system works fine. The second time no.
In this moment, when the path.txt is created, It have a line with the executable path and one second line empty. This line empty have a behavior like “press Enter” and runs Blender and the blender file isn’t created.
If i delete this line empty and save the file, Blender not run and a Blender file is created properly.
I think your problem may be that puts appends a newline end to what it writes into the text file. You can remove this with String#chomp. Alternatively, you can avoid the newline by using print instead of puts (provided $\ is still at its default value of nil).
John raises a good point: if the app has been normally installed so that it is in the system’s search path, you shouldn’t need to get the full absolute path to run it.