我是Cocoa和AppleScript的新手。最近我想通过"做shell脚本"做一些事情。在Cocoa-AppleScript中多次命令,并同时显示一个带有进度条的窗口,以指示我已完成的次数。
我的代码如下所示:
property progressBar: missing value
on applicationWillFinishLaunching_(aNotification)
repeat with i from 1 to 8
set progressBar's doublevalue to i
do shell script "sleep 1"
delay 1
end repeat
end applicationWillFinishLaunching_
这将显示进度条并指示进度。但是,包含进度条的窗口将处于非活动状态,直到重复完成。我认为这是因为Cocoa-AppleScript应用程序只有一个线程所以当它执行"做shell脚本时#34;命令GUI只是无法处理其他事件。我试图让shellcript在背景中运行,并且有一个尾部"&",但它的行为就像被绞死一样,但仍然耗费了大量时间。
我认为即使是"做shell脚本"命令可以在后台完成我还需要在完成更新进度条时收到通知,但我不知道如何实现。
所以我的问题是:如何通过"做shell脚本"异步,并在作业完成后通知Cocoa-AppleScript?
(顺便说一下,如果我删除"延迟1"行,进度条甚至不会更新,有人知道原因吗?)
答案 0 :(得分:0)
使用<?php
header('Access-Control-Allow-Origin: *');
error_reporting(E_ALL);
ini_set('display_errors',1);
session_start();
include_once 'dbconnect.php';
if(!isset($_SESSION['user']))
{
header("Location: index.php");
}
if(isset($_GET['points'])){
//Lightly sanitize the GET's to prevent SQL injections and possible XSS attacks
$points = strip_tags(mysql_real_escape_string($_GET['points']));
//$sql = mysql_query("INSERT INTO `publiadd_loginsx`.`users` (`points`) VALUES ('points');");
$sql = mysql_query("UPDATE `users` SET user_points = user_points +'$points' WHERE user_id = " . $_SESSION['user']);
if($sql){
//The query returned true - now do whatever you like here.
echo 'Your Points was saved. Congrats!';
}else{
//The query returned false - you might want to put some sort of error reporting here. Even logging the error to a text file is fine.
echo 'There was a problem saving your points. Please try again later.';
}
}else{
echo 'Your points wasnt passed in the request. Make sure you add ?name=NAME_HERE&score=1337 to the tags.';
}
// close MySQL connection
mysql_close();
?>
<html>
<head>
</head>
<body>
<body bgcolor="#ffffff">
</body>
</html>
。您需要使用几行ObjC来定义一个完成处理程序,该处理程序将回调到您的AS代码中,因为ASOC本身并不支持块,但除此之外它完全符合您的需要。