mirror of
https://gitlab.com/siarp/siarp.de.git
synced 2026-08-07 19:18:17 +00:00
1c6e73937f
* remove httrack meta files * rename site dir to "public"
453 lines
46 KiB
HTML
453 lines
46 KiB
HTML
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML+RDFa 1.0//EN"
|
||
"http://www.w3.org/MarkUp/DTD/xhtml-rdfa-1.dtd">
|
||
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" version="XHTML+RDFa 1.0" dir="ltr">
|
||
|
||
|
||
<!-- Mirrored from siarp.de/node/196 by HTTrack Website Copier/3.x [XR&CO'2014], Sun, 08 Dec 2019 12:01:12 GMT -->
|
||
<!-- Added by HTTrack --><meta http-equiv="content-type" content="text/html;charset=utf-8" /><!-- /Added by HTTrack -->
|
||
<head profile="http://www.w3.org/1999/xhtml/vocab">
|
||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||
<meta name="Generator" content="Drupal 7 (http://drupal.org)" />
|
||
<link rel="canonical" href="index.html" />
|
||
<link rel="shortlink" href="index.html" />
|
||
<title>Using AppleScript and cURL to import Content from iPhoto into Drupal | siarp.de</title>
|
||
<link type="text/css" rel="stylesheet" href="../../sites/siarp.de/files/css/css_xE-rWrJf-fncB6ztZfd2huxqgxu4WO-qwma6Xer30m4.css" media="all" />
|
||
<link type="text/css" rel="stylesheet" href="../../sites/siarp.de/files/css/css_NdVgz6YKifxQUEsW5xls_zI7Pn2F7E5U5Wb29zcu3vo.css" media="all" />
|
||
<link type="text/css" rel="stylesheet" href="../../sites/siarp.de/files/css/css_OAqUol8y_hmU_lCucLyaRX-a1G627sWWbvG_VG1GKnE.css" media="all" />
|
||
<link type="text/css" rel="stylesheet" href="../../sites/siarp.de/files/css/css_xPIRNNJGw8EiKyuE5b-xAtWWTQ8U1_huTr4xL09Dq2A.css" media="all" />
|
||
<link type="text/css" rel="stylesheet" href="../../sites/siarp.de/files/css/css_k3snrbsthqot7V7ccRZHS9OkCZkwBv4adtNieIVlbEU.css" media="print" />
|
||
|
||
<!--[if lt IE 7]>
|
||
<link type="text/css" rel="stylesheet" href="http://siarp.de/themes/garland/fix-ie.css?q26w7t" media="all" />
|
||
<![endif]-->
|
||
<script type="text/javascript" src="../../sites/siarp.de/files/js/js_qikmINIYTWe4jcTUn8cKiMr8bmSDiZB9LQqvceZ6wlM.js"></script>
|
||
<script type="text/javascript">
|
||
<!--//--><![CDATA[//><!--
|
||
jQuery.extend(Drupal.settings, {"basePath":"\/","pathPrefix":"","ajaxPageState":{"theme":"garland","theme_token":"gCW2x2SDT3XFdH1PNqCvlbb1tW7BMfme6fIHwusjp7g","js":{"misc\/jquery.js":1,"misc\/jquery-extend-3.4.0.js":1,"misc\/jquery.once.js":1,"misc\/drupal.js":1},"css":{"modules\/system\/system.base.css":1,"modules\/system\/system.menus.css":1,"modules\/system\/system.messages.css":1,"modules\/system\/system.theme.css":1,"modules\/comment\/comment.css":1,"modules\/field\/theme\/field.css":1,"modules\/node\/node.css":1,"modules\/user\/user.css":1,"sites\/all\/modules\/views\/css\/views.css":1,"sites\/all\/modules\/ctools\/css\/ctools.css":1,"public:\/\/geshi\/geshifilter-languages.css":1,"sites\/siarp.de\/modules\/geshifilter\/geshifilter.css":1,"themes\/garland\/style.css":1,"themes\/garland\/print.css":1,"themes\/garland\/fix-ie.css":1}}});
|
||
//--><!]]>
|
||
</script>
|
||
</head>
|
||
<body class="html not-front not-logged-in one-sidebar sidebar-second page-node page-node- page-node-196 node-type-story fluid-width" >
|
||
<div id="skip-link">
|
||
<a href="#main-content" class="element-invisible element-focusable">Skip to main content</a>
|
||
</div>
|
||
|
||
<div id="wrapper">
|
||
<div id="container" class="clearfix">
|
||
|
||
<div id="header">
|
||
<div id="logo-floater">
|
||
<div id="branding"><strong><a href="../../">
|
||
<span>siarp.de</span> </a></strong></div>
|
||
</div>
|
||
|
||
</div> <!-- /#header -->
|
||
|
||
|
||
<div id="center"><div id="squeeze"><div class="right-corner"><div class="left-corner">
|
||
<h2 class="element-invisible">You are here</h2><div class="breadcrumb"><a href="../../">Home</a></div> <a id="main-content"></a>
|
||
<div id="tabs-wrapper" class="clearfix"> <h1 class="with-tabs">Using AppleScript and cURL to import Content from iPhoto into Drupal</h1>
|
||
</div> <div class="clearfix">
|
||
<div class="region region-content">
|
||
<div id="block-system-main" class="block block-system clearfix">
|
||
|
||
|
||
<div class="content">
|
||
<div id="node-196" class="node node-story node-promoted">
|
||
|
||
|
||
|
||
<span class="submitted">7. February 2009 - 23:25 — <span class="username">Martin</span></span>
|
||
|
||
<div class="content clearfix">
|
||
<div class="field field-name-body field-type-text-with-summary field-label-hidden"><div class="field-items"><div class="field-item even"><p>I'm using Apple's iPhoto to organize my private photographs and Drupal is what comes to my mind first when there's need for a web-based solution. Having lots of pictures from a recent trip I want to show people I started thinking about some kind of web gallery. Being a developer I need to come up with something fancier than just some stock gallery product like <a href="http://gallery.menalto.com/">Gallery2</a> (actually I don't really know that product so bear with me). I did some research and found some article about different approaches to build photo galleries in Drupal and also a nice <a href="http://blip.tv/file/256997">video tutorial</a>. I've used image module and gallery module before but the flexibility that CCK extended by imagefield and imagecache and views seem to offer is just too tempting.
|
||
<!--break-->
|
||
But how would I get my hundreds of pictures imported into my yet-to-be-built gallery site? There are plenty of exporter plug-ins for iPhoto sending pictures to galleries like said Gallery2, Flickr and so on. I did not find much information on how to write a plug-in for iPhoto but I found some <a href="http://ruk.ca/article/2604">AppleScript code</a> that did just an export to Drupal. This one seemed to be very outdated but it was a good start. I started a <a href="http://lists.drupal.org/pipermail/development/2009-February/031849.html">thread on the Drupal developer mailing list</a> which gave me interesting options but I stayed with the concept of using cURL because it's the most flexible and probably the fasted way for my one-time requirement and there are no dependencies. The missing piece was this <a href="http://drupal.org/node/80548">handbook page</a> on d.o.</p>
|
||
|
||
<p><em><strong>Note</strong>: The following is a kind of tutorial but the result is just a custom script that needs to be adjusted to your scenario.</em></p>
|
||
|
||
<p>AppleScript is probably not the most powerful language but it allows us to call shell scripts. The idea is to get all the image information from iPhoto and then use shell commands to upload to a Drupal site. The first step is to extract the cURL commands from the PHP code from the handbook page so I don't need a separate script. Here are the shell commands to create content on a Drupal site:</p>
|
||
|
||
<p>First we log in which means getting a cookie with session data.</p>
|
||
|
||
<div class="geshifilter"><div class="bash geshifilter-bash">curl http:<span class="sy0">//</span>localhost<span class="sy0">/</span>drupal<span class="sy0">/</span>?<span class="re2">q</span>=user \<br />
|
||
<span class="re5">-s</span> \<br />
|
||
<span class="re5">-c</span> <span class="sy0">/</span>tmp<span class="sy0">/</span>curl-cookies.txt \<br />
|
||
<span class="re5">-b</span> <span class="sy0">/</span>tmp<span class="sy0">/</span>curl-cookies.txt \<br />
|
||
<span class="re5">-F</span> <span class="st_h">'name=user'</span> \<br />
|
||
<span class="re5">-F</span> <span class="st_h">'pass=pass'</span> \<br />
|
||
<span class="re5">-F</span> <span class="st_h">'form_id=user_login'</span> \<br />
|
||
<span class="re5">-F</span> <span class="st_h">'op=Log in'</span> \<br />
|
||
<span class="re5">--output</span> ~<span class="sy0">/</span>response_login.html</div></div>
|
||
|
||
<p>This calls the user page with your username and password. Check <span class="geshifilter"><code class="text geshifilter-text">response_login.html</code></span> to see if this has been successful.</p>
|
||
|
||
<p>Next we need to get the security token of the content creation form.</p>
|
||
|
||
<div class="geshifilter"><div class="bash geshifilter-bash">curl http:<span class="sy0">//</span>localhost<span class="sy0">/</span>drupal<span class="sy0">/</span>?<span class="re2">q</span>=node<span class="sy0">/</span>add<span class="sy0">/</span>image \<br />
|
||
<span class="re5">-s</span> \<br />
|
||
<span class="re5">-c</span> <span class="sy0">/</span>tmp<span class="sy0">/</span>curl-cookies.txt \<br />
|
||
<span class="re5">-b</span> <span class="sy0">/</span>tmp<span class="sy0">/</span>curl-cookies.txt \<br />
|
||
<span class="re5">--output</span> ~<span class="sy0">/</span>response_create_form.html</div></div>
|
||
|
||
<p>I'm using a custom content type called "image" – substitute that with whatever your content type is. <span class="geshifilter"><code class="text geshifilter-text">response_create_form.html</code></span> contains the HTML form to add an image including the security token which we can extract using a perl regular expression:</p>
|
||
|
||
<div class="geshifilter"><div class="perl geshifilter-perl"><a href="http://perldoc.perl.org/functions/s.html"><span class="kw3">s</span></a><span class="sy0">/.</span><span class="re0">*edit</span><span class="sy0">-</span>image<span class="sy0">-</span>node<span class="sy0">-</span>form<span class="sy0">-</span>form<span class="sy0">-</span>token<span class="st0">" *value="</span><span class="br0">(</span><span class="br0">[</span><span class="sy0">^</span><span class="st0">"]*)"</span><span class="sy0">.*/</span><span class="co3">$1</span><span class="sy0">/</span><a href="http://perldoc.perl.org/functions/s.html"><span class="kw3">s</span></a></div></div>
|
||
|
||
<p>Finally we actually upload our content.</p>
|
||
|
||
<div class="geshifilter"><div class="bash geshifilter-bash">curl http:<span class="sy0">//</span>localhost<span class="sy0">/</span>drupal<span class="sy0">/</span>?<span class="re2">q</span>=node<span class="sy0">/</span>add<span class="sy0">/</span>image \<br />
|
||
<span class="re5">-s</span> \<br />
|
||
<span class="re5">-c</span> <span class="sy0">/</span>tmp<span class="sy0">/</span>curl-cookies.txt \<br />
|
||
<span class="re5">-b</span> <span class="sy0">/</span>tmp<span class="sy0">/</span>curl-cookies.txt \<br />
|
||
<span class="re5">-F</span> <span class="st_h">'title=My Title'</span> \<br />
|
||
<span class="re5">-F</span> <span class="st_h">'field_image[0][fid]=0'</span> \<br />
|
||
<span class="re5">-F</span> <span class="st_h">'field_image[0][list]=1'</span> \<br />
|
||
<span class="re5">-F</span> <span class="st_h">'files[field_image_0]=@/Users/me/myimage.jpg'</span> \<br />
|
||
<span class="re5">-F</span> <span class="st_h">'body=My content.'</span> \<br />
|
||
<span class="re5">-F</span> <span class="st_h">'name=Myself'</span> \<br />
|
||
<span class="re5">-F</span> <span class="st_h">'status=1'</span> \<br />
|
||
<span class="re5">-F</span> <span class="st_h">'revision=1'</span> \<br />
|
||
<span class="re5">-F</span> <span class="st_h">'op=Save'</span> \<br />
|
||
<span class="re5">-F</span> <span class="st_h">'form_id=image_node_form'</span> \<br />
|
||
<span class="re5">-F</span> <span class="st_h">'form_token=63fe773e820d2a4565720ab3bd0fc991'</span> \</div></div>
|
||
|
||
<p>Check your Drupal site – there should be new content. My content type contains an <a href="http://drupal.org/project/imagefield">imagefield</a> that takes the above values. The "@" makes cURL upload the actual file.</p>
|
||
|
||
<p>Now to upload all selected images in iPhoto to the Drupal site I merge the snippets above with the AppleScript from iPhotoToDrupal:</p>
|
||
|
||
<p><em><strong>Update:</strong> I had an issue with special characters as I entered "'" in iPhoto's description field. I found out about <span class="geshifilter"><code class="applescript geshifilter-applescript"><span class="kw1">quoted form</span> <span class="kw3">of</span> variablename</code></span> which is used to escape strings in AppleScript to use them in shell scripts. This funtion puts the string in single quotes automatically so I couldn't use it like <span class="geshifilter"><code class="applescript geshifilter-applescript"><span class="st0">" -F 'body="</span> <span class="sy0">&</span> <span class="kw1">quoted form</span> <span class="kw3">of</span> this_comment <span class="sy0">&</span> <span class="st0">"'"</span></code></span>. Fortunately it's also possible to quote the value only like <span class="geshifilter"><code class="text geshifilter-text">-F body='xxx'</code></span> so <span class="geshifilter"><code class="applescript geshifilter-applescript"><span class="st0">" -F body="</span> <span class="sy0">&</span> <span class="kw1">quoted form</span> <span class="kw3">of</span> this_comment</code></span> works. Just being at it I replaced it for other variables also. Finally, I added a "Done" dialog.</em></p>
|
||
|
||
<div class="geshifilter"><div class="applescript geshifilter-applescript"><span class="kw3">set</span> DrupalUsername <span class="kw3">to</span> <span class="st0">"user"</span><br />
|
||
<span class="kw3">set</span> DrupalPassword <span class="kw3">to</span> <span class="st0">"pass"</span><br />
|
||
<span class="kw3">set</span> DrupalSite <span class="kw3">to</span> <span class="st0">"http://localhost/drupal/"</span><br />
|
||
<span class="kw3">set</span> DrupalContentType <span class="kw3">to</span> <span class="st0">"image"</span><br />
|
||
<span class="kw3">set</span> DrupalAddPage <span class="kw3">to</span> <span class="st0">"?q=node/add/"</span> <span class="sy0">&</span> DrupalContentType<br />
|
||
<span class="kw3">set</span> CookieFile <span class="kw3">to</span> <span class="st0">"/tmp/curl-cookies.txt"</span><br />
|
||
<br />
|
||
<br />
|
||
<span class="kw3">set</span> curlLogin <span class="kw3">to</span> <span class="st0">"curl"</span><br />
|
||
<span class="kw3">set</span> curlLogin <span class="kw3">to</span> curlLogin <span class="sy0">&</span> <span class="st0">" "</span> <span class="sy0">&</span> DrupalSite <span class="sy0">&</span> <span class="st0">"?q=user"</span><br />
|
||
<span class="kw3">set</span> curlLogin <span class="kw3">to</span> curlLogin <span class="sy0">&</span> <span class="st0">" -s"</span><br />
|
||
<span class="kw3">set</span> curlLogin <span class="kw3">to</span> curlLogin <span class="sy0">&</span> <span class="st0">" -c "</span> <span class="sy0">&</span> CookieFile<br />
|
||
<span class="kw3">set</span> curlLogin <span class="kw3">to</span> curlLogin <span class="sy0">&</span> <span class="st0">" -b "</span> <span class="sy0">&</span> CookieFile<br />
|
||
<span class="kw3">set</span> curlLogin <span class="kw3">to</span> curlLogin <span class="sy0">&</span> <span class="st0">" -F 'name="</span> <span class="sy0">&</span> DrupalUsername <span class="sy0">&</span> <span class="st0">"'"</span><br />
|
||
<span class="kw3">set</span> curlLogin <span class="kw3">to</span> curlLogin <span class="sy0">&</span> <span class="st0">" -F 'pass="</span> <span class="sy0">&</span> DrupalPassword <span class="sy0">&</span> <span class="st0">"'"</span><br />
|
||
<span class="kw3">set</span> curlLogin <span class="kw3">to</span> curlLogin <span class="sy0">&</span> <span class="st0">" -F 'op=Log in'"</span><br />
|
||
<span class="kw3">set</span> curlLogin <span class="kw3">to</span> curlLogin <span class="sy0">&</span> <span class="st0">" -F 'form_id=user_login'"</span><br />
|
||
<span class="kw1">do shell script</span> curlLogin<br />
|
||
<br />
|
||
<span class="kw3">set</span> curlAddForm <span class="kw3">to</span> <span class="st0">"curl"</span><br />
|
||
<span class="kw3">set</span> curlAddForm <span class="kw3">to</span> curlAddForm <span class="sy0">&</span> <span class="st0">" "</span> <span class="sy0">&</span> DrupalSite <span class="sy0">&</span> DrupalAddPage<br />
|
||
<span class="kw3">set</span> curlAddForm <span class="kw3">to</span> curlAddForm <span class="sy0">&</span> <span class="st0">" -s"</span><br />
|
||
<span class="kw3">set</span> curlAddForm <span class="kw3">to</span> curlAddForm <span class="sy0">&</span> <span class="st0">" -c "</span> <span class="sy0">&</span> CookieFile<br />
|
||
<span class="kw3">set</span> curlAddForm <span class="kw3">to</span> curlAddForm <span class="sy0">&</span> <span class="st0">" -b "</span> <span class="sy0">&</span> CookieFile<br />
|
||
<span class="kw3">set</span> tokenSrc <span class="kw3">to</span> <span class="kw1">do shell script</span> curlAddForm<br />
|
||
<br />
|
||
<span class="kw3">set</span> token <span class="kw3">to</span> <span class="kw1">do shell script</span> <span class="st0">"echo '"</span> <span class="sy0">&</span> tokenSrc <span class="sy0">&</span> <span class="st0">"' | perl -pe 's/.*edit-"</span> <span class="sy0">&</span> DrupalContentType <span class="sy0">&</span> <span class="st0">"-node-form-form-token<span class="es0">\"</span> *value=<span class="es0">\"</span>([^<span class="es0">\"</span>]*)<span class="es0">\"</span>.*/$1/s';"</span><br />
|
||
<br />
|
||
<br />
|
||
<span class="kw3">tell</span> <span class="kw1">application</span> <span class="st0">"iPhoto"</span><br />
|
||
<span class="kw1">activate</span><br />
|
||
<br />
|
||
<span class="kw3">try</span><br />
|
||
<span class="kw3">copy</span> <span class="br0">(</span><span class="kw3">my</span> selected_images<span class="br0">(</span><span class="br0">)</span><span class="br0">)</span> <span class="kw3">to</span> these_images<br />
|
||
<br />
|
||
<span class="co1">-- Make sure we have one or more image selected, and if we do, then grab the details of each and upload</span><br />
|
||
<span class="kw3">if</span> these_images <span class="kw3">is</span> <span class="kw1">false</span> <span class="kw2">or</span> <span class="br0">(</span><span class="kw2">the</span> <span class="kw1">count</span> <span class="kw3">of</span> these_images<span class="br0">)</span> <span class="kw3">is</span> <span class="nu0">0</span> <span class="kw3">then</span><br />
|
||
<span class="kw3">error</span> <span class="st0">"Please select one or more images."</span><br />
|
||
<span class="kw3">end</span> <span class="kw3">if</span><br />
|
||
<br />
|
||
<span class="kw3">repeat</span> <span class="kw3">with</span> this_image <span class="kw3">in</span> these_images<br />
|
||
<br />
|
||
<span class="kw3">set</span> this_imagefile <span class="kw3">to</span> <span class="br0">(</span><span class="br0">(</span>image path <span class="kw3">of</span> this_image<span class="br0">)</span> <span class="kw2">as</span> <span class="kw1">POSIX file</span><span class="br0">)</span><br />
|
||
<span class="kw3">set</span> this_uploadfile <span class="kw3">to</span> <span class="br0">(</span><span class="kw1">POSIX path</span> <span class="kw3">of</span> this_imagefile<span class="br0">)</span><br />
|
||
<span class="kw3">set</span> this_comment <span class="kw3">to</span> <span class="br0">(</span><span class="kw2">the</span> comment <span class="kw3">of</span> this_image<span class="br0">)</span> <span class="kw2">as</span> <span class="kw1">string</span><br />
|
||
<span class="kw3">set</span> this_name <span class="kw3">to</span> <span class="kw2">the</span> title <span class="kw3">of</span> this_image<br />
|
||
<br />
|
||
<span class="kw3">set</span> curlCreate <span class="kw3">to</span> <span class="st0">"curl"</span><br />
|
||
<span class="kw3">set</span> curlCreate <span class="kw3">to</span> curlCreate <span class="sy0">&</span> <span class="st0">" "</span> <span class="sy0">&</span> DrupalSite <span class="sy0">&</span> DrupalAddPage<br />
|
||
<span class="kw3">set</span> curlCreate <span class="kw3">to</span> curlCreate <span class="sy0">&</span> <span class="st0">" -s"</span><br />
|
||
<span class="kw3">set</span> curlCreate <span class="kw3">to</span> curlCreate <span class="sy0">&</span> <span class="st0">" -c "</span> <span class="sy0">&</span> CookieFile<br />
|
||
<span class="kw3">set</span> curlCreate <span class="kw3">to</span> curlCreate <span class="sy0">&</span> <span class="st0">" -b "</span> <span class="sy0">&</span> CookieFile<br />
|
||
<span class="kw3">set</span> curlCreate <span class="kw3">to</span> curlCreate <span class="sy0">&</span> <span class="st0">" -F title="</span> <span class="sy0">&</span> <span class="kw1">quoted form</span> <span class="kw3">of</span> this_name<br />
|
||
<span class="kw3">set</span> curlCreate <span class="kw3">to</span> curlCreate <span class="sy0">&</span> <span class="st0">" -F field_image[0][fid]=0"</span><br />
|
||
<span class="kw3">set</span> curlCreate <span class="kw3">to</span> curlCreate <span class="sy0">&</span> <span class="st0">" -F field_image[0][list]=1"</span><br />
|
||
<span class="kw3">set</span> curlCreate <span class="kw3">to</span> curlCreate <span class="sy0">&</span> <span class="st0">" -F files[field_image_0]=@"</span> <span class="sy0">&</span> <span class="kw1">quoted form</span> <span class="kw3">of</span> this_uploadfile<br />
|
||
<span class="kw3">set</span> curlCreate <span class="kw3">to</span> curlCreate <span class="sy0">&</span> <span class="st0">" -F body="</span> <span class="sy0">&</span> <span class="kw1">quoted form</span> <span class="kw3">of</span> this_comment<br />
|
||
<span class="kw3">set</span> curlCreate <span class="kw3">to</span> curlCreate <span class="sy0">&</span> <span class="st0">" -F name="</span> <span class="sy0">&</span> <span class="kw1">quoted form</span> <span class="kw3">of</span> DrupalUsername<br />
|
||
<span class="kw3">set</span> curlCreate <span class="kw3">to</span> curlCreate <span class="sy0">&</span> <span class="st0">" -F status=1"</span><br />
|
||
<span class="kw3">set</span> curlCreate <span class="kw3">to</span> curlCreate <span class="sy0">&</span> <span class="st0">" -F revision=1"</span><br />
|
||
<span class="kw3">set</span> curlCreate <span class="kw3">to</span> curlCreate <span class="sy0">&</span> <span class="st0">" -F op="</span><br />
|
||
<span class="kw3">set</span> curlCreate <span class="kw3">to</span> curlCreate <span class="sy0">&</span> <span class="st0">" -F form_id="</span> <span class="sy0">&</span> DrupalContentType <span class="sy0">&</span> <span class="st0">"_node_form"</span><br />
|
||
<span class="kw3">set</span> curlCreate <span class="kw3">to</span> curlCreate <span class="sy0">&</span> <span class="st0">" -F form_token="</span> <span class="sy0">&</span> token<br />
|
||
<span class="kw1">do shell script</span> curlCreate<br />
|
||
<br />
|
||
<span class="kw3">end</span> <span class="kw3">repeat</span><br />
|
||
<br />
|
||
<span class="kw3">on</span> <span class="kw3">error</span> error_message <span class="kw1">number</span> error_number<br />
|
||
<span class="kw3">if</span> <span class="kw2">the</span> error_number <span class="kw3">is</span> <span class="kw2">not</span> <span class="sy0">-</span><span class="nu0">128</span> <span class="kw3">then</span><br />
|
||
<span class="kw1">display dialog</span> error_message <span class="kw1">buttons</span> <span class="br0">{</span><span class="st0">"Cancel"</span><span class="br0">}</span> default button <span class="nu0">1</span><br />
|
||
<span class="kw3">end</span> <span class="kw3">if</span><br />
|
||
<span class="kw3">end</span> <span class="kw3">try</span><br />
|
||
<br />
|
||
<span class="kw3">end</span> <span class="kw3">tell</span><br />
|
||
<br />
|
||
<span class="kw1">display dialog</span> <span class="st0">"Done."</span> <span class="kw1">buttons</span> <span class="br0">{</span><span class="st0">"Ok"</span><span class="br0">}</span> default button <span class="nu0">1</span><br />
|
||
<br />
|
||
<br />
|
||
<span class="co1">-- Taken right out the "Show Image File" AppleScript on the Apple site:</span><br />
|
||
<span class="co1">-- http://www.apple.com/applescript/iphoto/</span><br />
|
||
<span class="kw3">on</span> selected_images<span class="br0">(</span><span class="br0">)</span><br />
|
||
<span class="kw3">tell</span> <span class="kw1">application</span> <span class="st0">"iPhoto"</span><br />
|
||
<span class="kw3">try</span><br />
|
||
<span class="co1">-- get selection</span><br />
|
||
<span class="kw3">set</span> these_items <span class="kw3">to</span> <span class="kw2">the</span> <span class="kw1">selection</span><br />
|
||
<span class="co1">-- check for single album selected</span><br />
|
||
<span class="kw3">if</span> <span class="kw2">the</span> class <span class="kw3">of</span> <span class="kw1">item</span> <span class="nu0">1</span> <span class="kw3">of</span> these_items <span class="kw3">is</span> album <span class="kw3">then</span> <span class="kw3">error</span><br />
|
||
<span class="co1">-- return the list of selected photos</span><br />
|
||
<span class="kw3">return</span> these_items<br />
|
||
<span class="kw3">on</span> <span class="kw3">error</span><br />
|
||
<span class="kw3">return</span> <span class="kw1">false</span><br />
|
||
<span class="kw3">end</span> <span class="kw3">try</span><br />
|
||
<span class="kw3">end</span> <span class="kw3">tell</span><br />
|
||
<span class="kw3">end</span> selected_images</div></div>
|
||
|
||
<p>Just go to iPhoto, select some images and start the script. The images including title and description will be uploaded as new nodes to your Drupal site.</p>
|
||
</div></div></div> </div>
|
||
|
||
<div class="clearfix">
|
||
<div class="links"><ul class="links inline"><li class="comment_forbidden first last"></li>
|
||
</ul></div>
|
||
|
||
<div id="comments" class="comment-wrapper">
|
||
<h2 class="title">Comments</h2>
|
||
|
||
<a id="comment-158"></a>
|
||
<div class="comment comment-by-anonymous odd">
|
||
|
||
<div class="clearfix">
|
||
|
||
<span class="submitted">30. June 2010 - 0:22 — <span class="username">Tony</span></span>
|
||
|
||
|
||
|
||
<h3><a href="../../comment/158/#comment-158" class="permalink" rel="bookmark">Der Inhalt dieses Feldes wird nicht öffentlich zugänglich angeze</a></h3>
|
||
|
||
<div class="content">
|
||
<div class="field field-name-comment-body field-type-text-long field-label-hidden"><div class="field-items"><div class="field-item even"><p>Hi-</p>
|
||
|
||
<p>Nice job. I've been trying to use your applescript but am getting an error, "the command exited with a non-zero status". My Drupal install has clean URLs on. Do I need to modify the strings in your script to fit, or will the "non-clean" URLs still work?</p>
|
||
|
||
<p>Here's the details on my parts:
|
||
Drupal 6.17
|
||
iPhoto 7.1.5 (aka iPhoto '08)</p>
|
||
|
||
<p>Thanks!</p>
|
||
</div></div></div> </div>
|
||
</div>
|
||
|
||
<ul class="links inline"><li class="comment_forbidden first last"></li>
|
||
</ul></div>
|
||
<a id="comment-200"></a>
|
||
<div class="comment comment-by-anonymous even">
|
||
|
||
<div class="clearfix">
|
||
|
||
<span class="submitted">29. March 2012 - 18:40 — <span class="username">Anonym</span></span>
|
||
|
||
|
||
|
||
<h3><a href="../../comment/200/#comment-200" class="permalink" rel="bookmark">I needed to change reg regex....</a></h3>
|
||
|
||
<div class="content">
|
||
<div class="field field-name-comment-body field-type-text-long field-label-hidden"><div class="field-items"><div class="field-item even"><p>In my Drupal 7.12 i needed to alter your regex line :</p>
|
||
|
||
<div class="geshifilter"><div class="text geshifilter-text">set token to do shell script "echo '" & tokenSrc & "' | perl -pe 's/.*edit-" & DrupalContentType & "-node-form-form-token\" *value=\"([^\"]*)\".*/$1/s';"</div></div>
|
||
|
||
<p>to:</p>
|
||
|
||
<div class="geshifilter"><div class="text geshifilter-text">set token to do shell script "echo '" & tokenSrc & "' | grep form_token | perl -pe 's/.*name=\"form_token\" *value=\"([^\"]*)\".*/$1/s';"</div></div>
|
||
|
||
<p>Somehow the name attribute was "form_token" and not "edit-image-node-form-form-token" as your code suggested.</p>
|
||
|
||
<p>Now it works great. Thanks for sharing!</p>
|
||
|
||
<p>I also added on the fly image resizing. All credits here go to https://discussions.apple.com/thread/2174350?start=0&tstart=0 from where I borrowed the resize code.</p>
|
||
|
||
<div class="geshifilter"><div class="text geshifilter-text">set longest_side to 1024<br />
|
||
<br />
|
||
set DrupalUsername to "admin"<br />
|
||
set DrupalPassword to "XXXXXX"<br />
|
||
set DrupalSite to "http://localhost/~arminhelbach/drupal7/"<br />
|
||
set DrupalContentType to "image"<br />
|
||
set DrupalAddPage to "?q=node/add/" & DrupalContentType<br />
|
||
set CookieFile to "/tmp/curl-cookies.txt"<br />
|
||
set tmp_path to "/tmp"<br />
|
||
<br />
|
||
set curlLogin to "curl"<br />
|
||
set curlLogin to curlLogin & " " & DrupalSite & "?q=user"<br />
|
||
set curlLogin to curlLogin & " -s"<br />
|
||
set curlLogin to curlLogin & " -c " & CookieFile<br />
|
||
set curlLogin to curlLogin & " -b " & CookieFile<br />
|
||
set curlLogin to curlLogin & " -F 'name=" & DrupalUsername & "'"<br />
|
||
set curlLogin to curlLogin & " -F 'pass=" & DrupalPassword & "'"<br />
|
||
set curlLogin to curlLogin & " -F 'op=Log in'"<br />
|
||
set curlLogin to curlLogin & " -F 'form_id=user_login'"<br />
|
||
do shell script curlLogin<br />
|
||
<br />
|
||
set curlAddForm to "curl"<br />
|
||
set curlAddForm to curlAddForm & " " & DrupalSite & DrupalAddPage<br />
|
||
set curlAddForm to curlAddForm & " -s"<br />
|
||
set curlAddForm to curlAddForm & " -c " & CookieFile<br />
|
||
set curlAddForm to curlAddForm & " -b " & CookieFile<br />
|
||
set tokenSrc to do shell script curlAddForm<br />
|
||
<br />
|
||
set token to do shell script "echo '" & tokenSrc & "' | grep form_token | perl -pe 's/.*name=\"form_token\" *value=\"([^\"]*)\".*/$1/s';"<br />
|
||
<br />
|
||
tell application "iPhoto"<br />
|
||
activate<br />
|
||
<br />
|
||
try<br />
|
||
copy (my selected_images()) to these_images<br />
|
||
<br />
|
||
-- Make sure we have one or more image selected, and if we do, then grab the details of each and upload<br />
|
||
if these_images is false or (the count of these_images) is 0 then<br />
|
||
error "Please select one or more images."<br />
|
||
end if<br />
|
||
<br />
|
||
repeat with this_image in these_images<br />
|
||
<br />
|
||
set this_imagefile to ((image path of this_image) as POSIX file)<br />
|
||
<br />
|
||
set this_comment to (the comment of this_image) as string<br />
|
||
set this_name to the title of this_image<br />
|
||
<br />
|
||
tell application "Image Events" to set t to PNG<br />
|
||
copy (my convert_image(this_imagefile as alias, tmp_path, longest_side)) to tmpimagefile<br />
|
||
set this_uploadfile to (POSIX path of tmpimagefile)<br />
|
||
<br />
|
||
set curlCreate to "curl"<br />
|
||
set curlCreate to curlCreate & " " & DrupalSite & DrupalAddPage<br />
|
||
set curlCreate to curlCreate & " -s"<br />
|
||
set curlCreate to curlCreate & " -c " & CookieFile<br />
|
||
set curlCreate to curlCreate & " -b " & CookieFile<br />
|
||
set curlCreate to curlCreate & " -F title=" & quoted form of this_name<br />
|
||
set curlCreate to curlCreate & " -F field_image[und][0][fid]=0"<br />
|
||
set curlCreate to curlCreate & " -F field_image[und][0][list]=1"<br />
|
||
set curlCreate to curlCreate & " -F files[field_image_und_0]=@" & quoted form of this_uploadfile<br />
|
||
set curlCreate to curlCreate & " -F body=" & quoted form of this_comment<br />
|
||
set curlCreate to curlCreate & " -F name=" & quoted form of DrupalUsername<br />
|
||
set curlCreate to curlCreate & " -F status=1"<br />
|
||
set curlCreate to curlCreate & " -F revision=1"<br />
|
||
set curlCreate to curlCreate & " -F op="<br />
|
||
set curlCreate to curlCreate & " -F form_id=" & DrupalContentType & "_node_form"<br />
|
||
set curlCreate to curlCreate & " -F form_token=" & token<br />
|
||
do shell script curlCreate<br />
|
||
<br />
|
||
do shell script "rm '" & this_uploadfile & "'"<br />
|
||
end repeat<br />
|
||
<br />
|
||
on error error_message number error_number<br />
|
||
if the error_number is not -128 then<br />
|
||
display dialog error_message buttons {"Cancel"} default button 1<br />
|
||
end if<br />
|
||
end try<br />
|
||
<br />
|
||
end tell<br />
|
||
<br />
|
||
display dialog "Done." buttons {"Ok"} default button 1<br />
|
||
<br />
|
||
<br />
|
||
-- Taken right out the "Show Image File" AppleScript on the Apple site:<br />
|
||
-- http://www.apple.com/applescript/iphoto/<br />
|
||
on selected_images()<br />
|
||
tell application "iPhoto"<br />
|
||
try<br />
|
||
-- get selection<br />
|
||
set these_items to the selection<br />
|
||
-- check for single album selected<br />
|
||
if the class of item 1 of these_items is album then error<br />
|
||
-- return the list of selected photos<br />
|
||
return these_items<br />
|
||
on error<br />
|
||
return false<br />
|
||
end try<br />
|
||
end tell<br />
|
||
end selected_images<br />
|
||
<br />
|
||
<br />
|
||
on convert_image(this_item, target_path, longest_side)<br />
|
||
tell application "Image Events"<br />
|
||
try<br />
|
||
launch<br />
|
||
-- open the image file<br />
|
||
set this_image to open this_item<br />
|
||
tell application "Finder"<br />
|
||
set new_item to ((target_path) as string) & (name of this_item) & ".jpg"<br />
|
||
end tell<br />
|
||
copy dimensions of this_image to {current_width, current_height}<br />
|
||
if current_width is greater than current_height then<br />
|
||
set new_height to (longest_side * current_height) / current_width<br />
|
||
if (new_height * longest_side) < (current_width * current_height) then<br />
|
||
scale this_image to size longest_side<br />
|
||
end if<br />
|
||
else<br />
|
||
if (new_height * longest_side) < (current_width * current_height) then<br />
|
||
set new_height to (longest_side * current_width) / current_height<br />
|
||
scale this_image to size new_height<br />
|
||
end if<br />
|
||
end if<br />
|
||
save this_image in new_item as JPEG<br />
|
||
return new_item<br />
|
||
on error msg<br />
|
||
return msg<br />
|
||
end try<br />
|
||
end tell<br />
|
||
end convert_image</div></div>
|
||
</div></div></div> </div>
|
||
</div>
|
||
|
||
<ul class="links inline"><li class="comment_forbidden first last"></li>
|
||
</ul></div>
|
||
|
||
</div>
|
||
</div>
|
||
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
<div class="region region-footer">
|
||
<div id="block-block-3" class="block block-block clearfix">
|
||
|
||
|
||
<div class="content">
|
||
<p>Alle Rechte liegen bei siarp.</p>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
</div></div></div></div> <!-- /.left-corner, /.right-corner, /#squeeze, /#center -->
|
||
|
||
<div id="sidebar-second" class="sidebar">
|
||
<div class="region region-sidebar-second">
|
||
<div id="block-menu-menu-autoren" class="block block-menu clearfix">
|
||
|
||
<h2 class="title">Written by</h2>
|
||
|
||
<div class="content">
|
||
<ul class="menu"><li class="first leaf"><a href="../../blog/2/">Martin</a></li>
|
||
<li class="last leaf"><a href="../../blog/3/">Tilman</a></li>
|
||
</ul> </div>
|
||
</div>
|
||
</div>
|
||
</div>
|
||
|
||
</div> <!-- /#container -->
|
||
</div> <!-- /#wrapper -->
|
||
</body>
|
||
|
||
<!-- Mirrored from siarp.de/node/196 by HTTrack Website Copier/3.x [XR&CO'2014], Sun, 08 Dec 2019 12:01:16 GMT -->
|
||
</html>
|