我为学校编写了一个脚本,用于打开所选科目的文件夹和电子书。您键入要访问的主题,然后它会为您打开该主题的文件夹(在应用程序的资源文件夹中)。但是,有些科目有电子书,所以如果主题有一个,我已经让剧本显示choose from list
。这很好用,我可以从列表中选择两个结果,这样就可以了。当我开始没有电子书的主题(所以他们不需要choose from list
)它没有工作时。比方说,Drama没有电子书,所以如果我输入"戏剧"它会立即打开文件夹。这就是我到目前为止所拥有的;任何人都可以告诉我它为什么不起作用?:
set subjectsWithEbook to {"History", "Science", "Maths", "French"}
display dialog "What subject would you like to access?" default answer ""
set theSubject to text returned of the result
if theSubject is in subjectsWithEbook then
choose from list {"Open folder", "Open eBook"} with prompt "What to open?"
set theResult to item 1 of the result
if theResult is "Open eBook" and theSubject is "history" then
tell application "Safari"
activate
open location ""
end tell
else
if theResult is "Open folder" and theSubject is "history" then
tell application "Finder" to open folder ((path to me as string) & "Contents:Resources:Subjects:History")
else
if theResult is "Open eBook" and theSubject is "science" then
tell application "Safari"
activate
open location ""
end tell
else
if theResult is "Open folder" and theSubject is "science" then
tell application "Finder" to open folder ((path to me as string) & "Contents:Resources:Subjects:Science")
else
if theResult is "Open eBook" and theSubject is "french" then
tell application "Safari"
activate
open location ""
end tell
else
if theResult is "Open folder" and theSubject is "french" then
tell application "Finder" to open folder ((path to me as string) & "Contents:Resources:Subjects:French")
else
if theResult is "Open eBook" and theSubject is "maths" then
tell application "Preview" to open (path to me as string) & "Contents:Resources:maths_ebook.pdf"
else
if theResult is "Open folder" and theSubject is "maths" then
tell application "Finder" to open folder ((path to me as string) & "Contents:Resources:Subjects:Maths")
else
if theSubject contains "Drama" then
tell application "Finder" to open folder ((path to me as string) & "Contents:Resources:Subjects:Drama")
end if
end if
end if
end if
end if
end if
end if
end if
end if
end if
答案 0 :(得分:1)
为了适应所有情况,甚至更多,我使用记录数据结构更新了我的第一个脚本,如前所述。
您现在可以定义所需的主题,以及每个主题要打开的文件夹(如果有)或电子书。对于电子书,您还可以定义要用于打开的应用程序:例如,它可以是"预览"对于PDF文件,如果电子书记录包含URL,则为Safari。
在我的例子中,我为Drama添加了一个txt文件,该文件必须通过TextEdit打开。
对于数学,这是一个通过预览
打开的pdf对于历史记录,这是一个通过Safari打开的URL(google!)。
这只是为了向您展示您可以对此新脚本执行任何操作。 (我添加了很多评论)
function createTextureFromArray(gl, dataArray, type, width, height) {
var data = new Uint8Array(dataArray);
var texture = gl.createTexture();
gl.bindTexture(gl.TEXTURE_2D, texture);
gl.texImage2D(gl.TEXTURE_2D, 0, type, width, height, 0, type, gl.UNSIGNED_BYTE, data);
return texture;
}
var arrayBuffer = new ArrayBuffer(640*480);
for (var i=0; i < 640; i++) {
for (var j=0; j < 480; j++) {
arrayBuffer[i] = Math.floor(Math.random() * 255) + 0; //filling buffer with random data between 0 and 255 which will be further filled to the texture
//NOTE : above data is just dummy data , I will get this data from server pixel by pixel.
}
}
var gl = canvas.getContext('webgl');
// setup GLSL program
var program = createProgramFromScripts(gl, ["2d-vertex-shader", "2d-fragment-shader"]);
gl.useProgram(program);
//what should I add after this ?