Making folders/directories with a shell script in an XCode application


I am running into a problem with a project I am working on. I am building a archive of all the photographs that have run in our magazines. Here’s the basic workflow:

User opens admin application (developed in XCode) to select a folder of jpeg files. The app then makes a call to a MySQL DB to get the next id number and renames the files by that number and in a sequential order, like this:


Then the user can enter a variety of information for that photo series, such as photographer, keywords, film type, restrictions, etc. etc. The user then clicks a button to add the record. When this happens the data is written to the appropriate fields in that photo series’ record, the app then checks to see if there is a folder for the series located on the server (in this case it would be a folder named 7001), if not it creates the folder using a shell script and then moves the files to the folder, if the folder exists it just moves the files. Here’s the shell script to do that:

tell application "Finder"
if exists seriesFolderPath then
do shell script "cp -R " & POSIX path of tempFolderPosix & " " & POSIX path of seriesFolderPath
do shell script "mkdir -v " & POSIX path of seriesFolderPath & "; cp -R " & POSIX path of tempFolderPosix & " " & POSIX path of seriesFolderPath
end if
end tell

Employees can then search this archive through a browser. I use PHP to make the SQL calls and display the results. In my PHP I use a function to read the film series folder and count the number of files located within. Here’s that portion of the code:

$path = “/Volumes/Cumulus/MerionPhotoArchive/” . $logNum . “/”;

$handle = opendir($path) or die(“Unable to open $path”);;
while ($file = readdir($handle)) {
if(stristr($file, $logNum . “-”) != FALSE) {
$fileCount = $fileCount + 1;

if ($fileCount > 6) {
$fileCount = 6;


I’m picking up someone else’s problem here and initially they had just one big folder with all the images (14,000 files) stored in them. This made admin on this folder a pain (say we had to remove a series for some reason - it took forever for this folder to open) so I changed the workflow so that each series went in its own folder, wrote a script to move everything where it belongs (using the same shell to create the folders that I am using in the XCode app).

Here’s my problem (thanks for bearing with me to this point).

PHP will recognize the folders created with the AppleScript but seemingly will not with the folders created through XCode. (Using the same shell script). Additionally, when I try to delete the folders created through XCode I get an error saying the .DS_Store file is in use. I can move them and rename them and my IT Server administrator was able to delete them.

One caveat is that the folders are being created on a Windows File Server, not sure if that has any bearing on XCode creating files. I’ve never had a problem before creating folders on this server using AS. Any thoughts or suggestions would be helpful. I haven’t tried just using the Finder to make the folders yet, that’s my next step.


I removed the shell script and went with this:

move entire contents of alias tempFolder to seriesFolderPath

same results though, the folder is not recognized by PHP.

IMHO <$handle = opendir($path) or die(“Unable to open $path”);;> has a “;” too many.
I made directories from 4 different “Wrappers” using the same code:
1)Run from Script Editor => “testingfromScript”
2)Run from Script Editor → Save as app => “testingfromScriptApp”
3)Run from XCode “testingfromXCode”
4)Run from compiled XCode AS app => “testingfromXCode2”

	tell application "Finder"
		set seriesFolderPath to ((choose folder) as Unicode text) & "testingfromScriptApp:"
		do shell script "mkdir -v " & POSIX path of seriesFolderPath
	end tell

I then copied a unique number of files into each folder and counted them from PHP.
I got correct results.

compare access privileges, maybe they are different depending on the Xcode or SE version

haven’t tested this:
Instead of
do shell script "mkdir -v " & POSIX path of seriesFolderPath
do shell script "mkdir -v " & quoted form of (POSIX path of seriesFolderPath)

does it make a difference whether you use a “-” or a “_” as “binder”?

good luck