鮨屋さんで展示

On July 31, 2010, in Photography, Uncategorized, by ryos

クパチーノにある Sushi-Ya Restaurant で10月半ばまで自然写真を展示させていただいています。お近くにお立ち寄りの際にはご覧ください。

For more information: http://ryosode.com/photography/2010/07/31/exhibit-sushi-ya-restaurant/

 

ryo sode photography

On July 22, 2010, in Art, Photography, by ryos

http://ryosode.com/photography/

I will be posting future photo updates on my new site. Please visit and subscribe to the RSS feed. Thanks!

 

Bottle Studies: Corzo Silver

On July 17, 2010, in Art, Photography, by ryos

Corzo - empty bottle

I came across a bottle of tequila. It’s called Corzo Silver Tequila. This is a sipping kind of tequila. Not recommended for shots. Real smooooth.

But something else is special about this tequila; the bottle. It’s a blocky rectangular shaped object made with a high quality thick glass. Sturdy and elegant.

When I finished its content, I knew I wasn’t gonna toss it away. I decided to give myself a creative art assignment.


Topic One: Fog Machine


Fog Machine Scene Two

Fog Machine Scene One


Topic Two: Dish Soap


Wet and Foamy One

Wet and Foamy Two


Topic Three: Lights Within


Starlights

Twilight

 

Executing AppleScript via php

On July 13, 2010, in AppleScript Tech, Tech, php, by ryos

AppleScript is often a frustrating piece of technology. It’s not as well documented as many other languages available on OS X.

However it’s also a technology that every Mac hacker I know had to use at one point. With right techniques and a right goal in mind, AppleScript delivers a result in a relatively short amount of time.

This brings me to the point of my post. I needed a quick way to implement a clickable UI to interact with user, from within php. This turns out to be a bit of challenge in php. Python and Ruby has Objective-C bridge, so they can literally write a Cocoa app whose controller is written in one of those languages. With php, we don’t have native way to create OS X UI application.

However on OS X, we have a handy UNIX command called “osascript” (located at /usr/bin/osascript). This command allows you to execute AppleScript commands from Terminal and actually retrieve a returned value. I wrote the following code to see if I can use osascript from inside php.

function osascript($script) {
	$response = my_exec("/usr/bin/osascript <<EOF
                            " . $script . "
                            EOF");
	if (!empty($response['return'])) {
		throw new Exception ($response['stderr']);
	}
	return trim($response['stdout']);
}

/**
 * copied from http://php.net/manual/en/function.system.php
 * returns an array of stdout, stderr, and return value from the systemcall
 */
function my_exec($cmd, $input='') {
	$proc=proc_open($cmd, array(0=>array('pipe', 'r'), 1=>array('pipe', 'w'), 2=>array('pipe', 'w')), $pipes);
	fwrite($pipes[0], $input);fclose($pipes[0]);
	$stdout=stream_get_contents($pipes[1]);fclose($pipes[1]);
	$stderr=stream_get_contents($pipes[2]);fclose($pipes[2]);
	$rtn=proc_close($proc);
	return array(
		'stdout'=>$stdout,
		'stderr'=>$stderr,
		'return'=>$rtn
	);
}

This turned out to be a perfect tool. I was able to execute a wide range of AppleScript code using the function. I wrote an additional utility function to translate a php array into an AppleScript list:

function php_array_to_applescript_list($an_array) {
	if (empty($an_array)) {
		throw new Exception ("empty array given");
	}

	$response = "{";
	for ($i = 0; $i < count($an_array); $i++) {
		$response .= '"'.$an_array[$i].'"';
		if ($i + 1 < count($an_array)) {
			$response .= ",";
		}
	}
	$response .= "}";
	return $response;
}

Finally, here is a sample code that generates a choice list UI.

// Selection UI
$choices = array("foo", "bar");
$choices_as = php_array_to_applescript_list($choices);
$osa_choose_from_list = '
set our_list to '.$choices_as.'
tell application "Finder"
	activate
	choose from list our_list with prompt "foo or bar!?"
end tell
';
$response = osascript($osa_choose_from_list);
println("You chose " . $response);

The UI looks like this:

Once the user makes a choice, I can retrieve this value back in php land. Pretty neat.

Here is the sample php file you can download.

Tagged with: