Install samba on OSX Lion

This is compiled from many sources and works with me.

 

  1. Install MacPorts (and XCode 4.1 before), there is a dmg for Lion at http://www.macports.org/install.php
  2. in Terminal > sudo port -d sync
  3. in Terminal > sudo port install samba3 I had to do it twice to go right
  4. in Terminal > sudo cp /opt/local/etc/samba3/smb.conf.sample \
    /opt/local/etc/samba3/smb.conf
    to copy the sample-config-file
  5. I like nano, that’s why I put in Terminal > sudo nano /opt/local/etc/samba3/smb.conf
    Now you have to edit your shares:
  6. [global]
    	workgroup = WORKGROUP
    	server string = myServer 

    [Music]
    	comment = Music
    	path = /Users/theUser/Music
    	available = yes
    	guest ok = yes
    	create mask = 644
    	directory mask = 755
    	read only = no 

    In nano to save press ^-X and y and enter the path which is given

  7. in Terminal > sudo nano /Library/LaunchDaemons/org.samba.smbd.plist and paste the follow text in it:
  8. <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
    <plist version="1.0">
    	<dict>
    		<key>Label</key>
    		<string>org.samba.smbd</string>
    		<key>OnDemand</key>
    		<false/>
    		<key>ProgramArguments</key>
    		<array>
    			<string>/opt/local/sbin/smbd</string>
    			<string>-F</string>
    		</array>
    		<key>RunAtLoad</key>
    		<true/>
    		<key>ServiceDescription</key>
    		<string>samba</string>
    	</dict>
    </plist>
  9. in Terminal > sudo nano /Library/LaunchDaemons/org.samba.nmbd.plist and paste the follow text in it:
  10. <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
    <plist version="1.0">
    	<dict>
    		<key>Label</key>
    		<string>org.samba.nmbd</string>
    		<key>OnDemand</key>
    		<false/>
    		<key>ProgramArguments</key>
    		<array>
    			<string>/opt/local/sbin/nmbd</string>
    			<string>-F</string>
    		</array>
    		<key>RunAtLoad</key>
    		<true/>
    		<key>ServiceDescription</key>
    		<string>netbios</string>
    	</dict>
    </plist>
  11. disable in System Preferences – Sharing – Options: SMB
  12. disable netbiosd-Daemon:
    sudo launchctl stop com.apple.netbiosd
    sudo launchctl unload -w /System/Library/LaunchDaemons/com.apple.netbiosd.plist
  13. start samba:
    sudo launchctl load /Library/LaunchDaemons/org.samba.smbd.plist
    sudo launchctl load /Library/LaunchDaemons/org.samba.nmbd.plist

Sometimes there is the need of a user and a password, for this type in terminal
>sudo smbpasswd -a <username>
You have to put in your password and that’s it!
To uninstall samba or macports see MacPort Guide

I found out, it is better to give the Server another name, not the sharing name in the Pref Panel

2 comments so far, add yours

OSX Lion Launchpad hide Apps

To hide some apps in the OSX LP there is a easy way.

 

At first it is recommended to put the apps on the last page or in a folder on the last position. For example I have a folder “CS5 other” and there I put all the Adobe Uninstaller in. Another one is the Solver-Add in for Excel. You can add to the list as many items as you want. Now there is a small script to hide (or unhide) the apps:

#!/bin/sh
DB=$(ls $HOME/Library/Application\ Support/Dock/*.db)
echo "$DB"
if [ -n "$1" ] ; then 
 	unhide="<"
else 
	unhide=">"
fi
sqlite3 "$DB" "Update apps set item_id = -1 * item_id where  \
	(title like \"%uninst%adobe%\" or \
	title like \"%Acrobat%uninst%\") \
	and item_id $unhide 0;"
sqlite3 "$DB" "Update apps set item_id = -1 * item_id where  \
	title like \"%Solver%\" \
	and item_id $unhide 0;"
killall Dock

 

Call the script maybe HideLP_Apps.sh, chmod the script 755 and use it.

When you add a parameter like

>HideLP_Apps.sh 1

then the apps appear again

Leave the first comment

The best way to do all the things in Aperture …

The best way to do all the things in Aperture ist a plug-in. It is quite easy to build a plug-in with the ApertureEditManager and ApertureExportManager.
I will upload an example to show the exif data of selected pictures, using ApertureEditManager und the exiftool, which is also included in the bundle. I think, this is faster and more reliable than a script. Just put it in the
/Library/Application Support/Aperture/Plug-Ins/Edit Folder and that’s it!

Leave the first comment

New Database access, the database isn’t locked anymore in Aperture 3.0.3

The Aperture3 database is not locked anymore.

That is why the script is a little bit easier without detour (nice guy ShooTerKo told me yesterday):


	#!/bin/sh

	PREFERENCE=""

	function workID {
	ID=$1
	master=$(sqlite3 "$DB" "Select masteruuid from RKVersion where uuid = '$ID';")
	name=$(sqlite3 "$DB" "Select name from RKVersion where uuid = '$ID';")
	imagePath=$(sqlite3 "$DB" "Select imagePath from RKMaster where uuid = '$master';")
	isRef=$(sqlite3 "$DB" "Select fileIsReference from RKMaster where uuid = '$master';")
	if [ 0 -eq $isRef ] ; then
		imagePath="$LIBRARY/Master/$imagePath"
		isRef=false
		else
		imagePath="/$imagePath"
		isRef=true
	fi
	echo "Name: '$name'\nFile referenced: $isRef\nPath: '$imagePath'\n"
	}

	function setPreference {
	# $1 key $2 Prefernce file
	PREFERENCE=$(osascript \
		-e 'tell application "System Events"'\
		-e "return value of property list item \"$1\" of ¬
		property list file ((path to preferences as Unicode text) & \"$2\")" \
		-e 'end tell')
	if [ ${PREFERENCE:0:1} = "~" ] ; then
		PREFERENCE="$HOME${PREFERENCE:1}"
	fi
	}

	setPreference "LibraryPath" "com.apple.Aperture.plist"
	LIBRARY="$PREFERENCE"
	DB="$LIBRARY/Database/Library.apdb"

	echo "\nStart script\n"
	theList=$(osascript \
		-e 'tell application "Aperture"' \
		-e 'set theList to "" ' \
		-e 'set imageSel to (get selection)' \
		-e 'if imageSel is {} then' \
		-e '   return ""' \
		-e 'else' \
		-e '   repeat with i from 1 to count of imageSel' \
		-e '      set theList to theList &  (id of item i of imageSel as rich text) & " "' \
		-e '   end repeat' \
		-e '   return theList ' \
		-e 'end if' \
		-e 'end tell'  )

	if [ -z "$theList" ] ; then
		echo "No picture selected, Cancel"
		exit
	else
		for ID in $theList ;do
		workID $ID
		done
	fi
	exit 0
Leave the first comment

A script to convert dmg- to iso-images

This script is found very often via google to convert a dmg into a iso-image. This is a enhanced version.
You don’t need to write the “.dmg” ending, but you can. The script tests if there are any given image-file or prints out a usage-message.


#!/bin/bash
if [ -z $1 ]; then
	bn=$(basename $0)
	echo
	echo "Usage: $bn <name of dmg-image>"
	echo
	exit 1
fi
e=$(echo $1 | sed s/.dmg$//g)
echo "Converting "$e".dmg to "$e".iso:"
hdiutil convert "$e".dmg -format UDTO -o "$e".iso
mv "$e".iso.cdr "$e".iso
exit 0
Leave the first comment

A simple Show Google Maps

This script takes the first image of selection and shows is on Google Maps. The GPS data are the Aperture tags Exif tag Latitude and Exif tag Longitude.


on run
	set output to return
	tell application "Aperture"
		set imageSel to (get selection)
	end tell
	if imageSel is {} then
		display dialog "Please select an image in Aperture" with title "Exif-Data" buttons {"Okay"}
		return
	else
		--		repeat with i from 1 to count of imageSel
		set p to item 1 of imageSel -- item i
		set aPath to getPath(p)
		--		set output to output & aPath & return
		set output to GetApertureGPS(p)
		if Latitude of output is not equal to "no Data" and Longitude of output is not equal to "no Data" then
			my ShowIt(output, aPath)
		else
			beep
			delay 1
			beep
		end if
		--		end repeat
	end if
end run

on ShowIt(coord, aFile)
	set la to Latitude of coord
	set lo to Longitude of coord
	set s to "<html><head> <meta name=\"viewport\" content=\"initial-scale=1.0, user-scalable=yes
		\" />\\n<meta http-equiv=\"content-type\" content=\"text/html; charset=UTF-8\"/>\\n
		<title>" & aFile & "</title>\\n<script type=\"text/javascript\" src=\"http:
		//maps.google.com/maps/api/js?sensor=false\"></script>\\n<script type=\"text/javascript\">
		\\nfunction initialize() { var myLatlng = new google.maps.LatLng("
	set s to s & inPoint(la) & "," & inPoint(lo)
	set s to s & "); \\nvar myOptions = { zoom: 15, center: myLatlng, mapTypeId:
		google.maps.MapTypeId.HYBRID } \\nvar map = new google.maps.Map
		(document.getElementById(\"map_canvas\"), myOptions); \\nvar infowindow = new google.maps.InfoWindow( { content: \"Zoom Level Test\", size: new google.maps.Size(50,50), position: myLatlng }); \\nvar marker =
		new google.maps.Marker({ position: myLatlng, map: map, draggable: true,
		title:\"Koordinaten:\\\\nLatitude: \" + myLatlng.lat() + \"\\\\n\" + \"Longitude: \" + myLatlng.lng() });
		\\ngoogle.maps.event.addListener(marker, \"dragend\", function() { var myPos = marker.getPosition();
		\\ninfowindow.setContent(\"<u>Koordinaten:</u><br><br>Latitude: \" + myPos.lat() +
		\"<br>Longitude: \" + myPos.lng() ); \\ninfowindow.setPosition(myPos); \\ninfowindow.open(map); });
		\\ngoogle.maps.event.addListener(marker, \"click\", function() { var myPos = marker.getPosition();
		\\ninfowindow.setContent(\"<u>Koordinaten:</u><br><br>Latitude: \" + myPos.lat() +
		\"<br>\" + \"Longitude: \" + myPos.lng()); \\ninfowindow.setPosition(myPos);
		\\ninfowindow.open(map); }); \\ngoogle.maps.event.addListener(marker, \"dragstart\",
		function() { infowindow.close(); }); } </script> \\n</head>\\n<body
		style=\"margin:0px; padding:0px;\" onload=\"initialize()\">\\n
		<div id=\"map_canvas\" style=\"width: 100%; height: 100%;\">\\n
		</div>\\n</body>\\n</html>"
	set aFile to (do shell script "/bin/echo $HOME")
	set aFile to aFile & "/fs" & (do shell script "date '+%Y%m%d%H%M%S'") & ".html"
	set command to "echo '" & s & "' > " & aFile
	do shell script command
	do shell script "open '" & aFile & "'"
	delay 2
	do shell script "rm '" & aFile & "'"
end ShowIt

on GetApertureGPS(aPic)
	set aLatitude to "no Data"
	set aLongitude to "no Data"
	tell application "Aperture"
		tell aPic
			try
				set aLatitude to (get value of EXIF tag "Latitude")
				set aLongitude to (get value of EXIF tag "Longitude")
			end try
		end tell
	end tell
	return {Latitude:aLatitude, Longitude:aLongitude}
end GetApertureGPS

on getPath(aItem)
	tell application "Aperture"
		tell library 1
			tell aItem
				set ImpGroup to (get value of other tag "ImportGroup")
				set MasterPath to my GetMasterPath(ImpGroup)
				set MasterFile to (get value of other tag "FileName")
			end tell
		end tell
	end tell
	set MasterPath to my getLibPath() & MasterPath
	set aPath to quoted form of (MasterPath & MasterFile)
	return aPath
end getPath

on GetMasterPath(aStr)
	set tid to AppleScript's text item delimiters
	set AppleScript's text item delimiters to "-"
	set aYear to text item 1 of aStr
	set aMonth to text item 2 of aStr
	set aRest to text item 3 of aStr
	set AppleScript's text item delimiters to " @ "
	set aDay to text item 1 of aRest
	set aRest to text item 2 of aRest
	set AppleScript's text item delimiters to ":"
	set anHour to text item 1 of aRest
	set aMinute to text item 2 of aRest
	set aRest to text item 3 of aRest
	set AppleScript's text item delimiters to " "
	set aSecond to text item 1 of aRest
	set AmPm to text item 2 of aRest
	if AmPm is equal to "PM" then
		set anHour to anHour + 12
	end if
	set AppleScript's text item delimiters to "/"
	set aRest to {"", "Masters", aYear, aMonth, aDay, aYear & aMonth & aDay & "-" & anHour & aMinute & aSecond, ""} as text
	set AppleScript's text item delimiters to tid
	return aRest
end GetMasterPath

on getLibPath()
	tell application "System Events" to set p_libPath to value of property list item "LibraryPath" of property list file ((path to preferences as Unicode text) & "com.apple.aperture.plist")

	if ((offset of "~" in p_libPath) is not 0) then
		set p_script to "/bin/echo $HOME"
		set p_homePath to (do shell script p_script)

		set p_offset to offset of "~" in p_libPath
		set p_path to text (p_offset + 1) thru -1 of p_libPath

		set g_libPath to p_homePath & p_path
		return g_libPath
	else
		return p_libPath
	end if

end getLibPath

on inPoint(aValue)
	return replacetext(aValue, character 2 of (2 / 3 as string), ".")
end inPoint

on replacetext(aStr, oldString, newString)
	log oldString
	log aStr
	set oldDelimiters to AppleScript's text item delimiters
	set AppleScript's text item delimiters to oldString
	set theArray to every text item of (aStr as text)
	set AppleScript's text item delimiters to newString
	set newStr to theArray as text
	set AppleScript's text item delimiters to oldDelimiters
	return newStr
end replacetext

Leave the first comment

Show only GPS exif data

This is a “short” version, it shows just the GPS exif data of the master.


on run
	set output to return
	tell application "Aperture"
		set imageSel to (get selection)
	end tell
	if imageSel is {} then
		display dialog "Please select an image in Aperture" with title "Exif-Data" buttons {"Okay"}
		return
	else
		--		repeat with i from 1 to count of imageSel
		set p to item 1 of imageSel -- item i
		set aPath to getPath(p)
		--		set output to output & aPath & return
		set output to GetApertureGPS(p)
		set output to output & GetExifTool(aPath)
		--		end repeat
	end if
	choose from list output with title "List Exif Metadata" with prompt "Picture:" & return & aPath
end run

on GetExifTool(myPath)
	set exiftool_args to "-g1 -S "
	set the_md to "--- GPS ---" & return & "No Data found!" & return & ""
	set tLat to ""
	set tLong to ""
	try
		set the_md to do shell script "/usr/bin/exiftool " & exiftool_args & " " & myPath & " | grep GPS"
		set tLat to do shell script "/usr/bin/exiftool -c \"%.8f\" " & exiftool_args & " " & myPath & " | grep GPSLatitude: | sed s/GPSLatitude:\\ //"
		set tLong to do shell script "/usr/bin/exiftool -c \"%.8f\" " & exiftool_args & " " & myPath & " | grep GPSLongitude: | sed s/GPSLongitude:\\ //"
	end try
	set textList to {}
	set textList to splittext(the_md, return)
	repeat with i from 1 to count textList
		set p to item i of textList as string
		if (p contains "GPSLongitude:") then
			set item i of textList to inNewdegreees(p, tLong)
		end if
		if (p contains "GPSLatitude:") then
			set item i of textList to inNewdegreees(p, tLat)
		end if
	end repeat
	return textList

end GetExifTool

on GetApertureGPS(aPic)
	set aLatitude to "no Data"
	set aLongitude to "no Data"
	set aAltitude to "no Data"
	set aGPSVersion to "no Data"
	tell application "Aperture"
		tell aPic
			try
				set aLatitude to (get value of EXIF tag "Latitude")
				set aLongitude to (get value of EXIF tag "Longitude")
				set aAltitude to (get value of EXIF tag "Altitude")
				set aGPSVersion to (get value of EXIF tag "GPSVersion")
			end try
		end tell
	end tell
	set AppleScript's text item delimiters to ""
	if aLongitude is not equal to "no Data" then
		set aLongitude to aLongitude & " (" & my inMinutes(aLongitude, false) & ")" as text
	end if
	if aLatitude is not equal to "no Data" then
		set aLatitude to aLatitude & " (" & my inMinutes(aLatitude, true) & ")" as text
	end if
	return {"--- Aperture ---", "Latitude: " & aLatitude, "Longitude: " & aLongitude, "Altitude: " & aAltitude, "GPSVersion: " & aGPSVersion, " "}
end GetApertureGPS

on getPath(aItem)
	tell application "Aperture"
		tell library 1
			tell aItem
				set ImpGroup to (get value of other tag "ImportGroup")
				set MasterPath to my GetMasterPath(ImpGroup)
				set MasterFile to (get value of other tag "FileName")
			end tell
		end tell
	end tell
	set MasterPath to my getLibPath() & MasterPath
	set aPath to quoted form of (MasterPath & MasterFile)
	return aPath
end getPath

on GetMasterPath(aStr)
	set tid to AppleScript's text item delimiters
	set AppleScript's text item delimiters to "-"
	set aYear to text item 1 of aStr
	set aMonth to text item 2 of aStr
	set aRest to text item 3 of aStr
	set AppleScript's text item delimiters to " @ "
	set aDay to text item 1 of aRest
	set aRest to text item 2 of aRest
	set AppleScript's text item delimiters to ":"
	set anHour to text item 1 of aRest
	set aMinute to text item 2 of aRest
	set aRest to text item 3 of aRest
	set AppleScript's text item delimiters to " "
	set aSecond to text item 1 of aRest
	set AmPm to text item 2 of aRest
	if AmPm is equal to "PM" then
		set anHour to anHour + 12
	end if
	set AppleScript's text item delimiters to "/"
	set aRest to {"", "Masters", aYear, aMonth, aDay, aYear & aMonth & aDay & "-" & anHour & aMinute & aSecond, ""} as text
	set AppleScript's text item delimiters to tid
	return aRest
end GetMasterPath

on getLibPath()
	tell application "System Events" to set p_libPath to value of property list item "LibraryPath" of property list file ((path to preferences as Unicode text) & "com.apple.aperture.plist")

	if ((offset of "~" in p_libPath) is not 0) then
		set p_script to "/bin/echo $HOME"
		set p_homePath to (do shell script p_script)

		set p_offset to offset of "~" in p_libPath
		set p_path to text (p_offset + 1) thru -1 of p_libPath

		set g_libPath to p_homePath & p_path
		return g_libPath
	else
		return p_libPath
	end if

end getLibPath

on inDeci(aValue)
	return replacetext(aValue, ".", (character 2 of (2 / 3 as string)))
end inDeci

on inMinutes(aValue, Lat)
	set aValue to inDeci(aValue)
	set degree to aValue
	if degree < 1 then
		set degree to degree * -1.0
		if Lat then
			set EWNS to "S"
		else
			set EWNS to "W"
		end if
	else
		if Lat then
			set EWNS to "N"
		else
			set EWNS to "E"
		end if
	end if
	set minute to (degree mod 1) * 60
	set degree to degree div 1
	set second to (minute mod 1) * 60
	set second to (doRound(second, 2))
	set second to my inPoint(second)
	set minute to minute div 1
	return degree & " deg " & minute & "' " & second & "\" " & EWNS
end inMinutes

on inPoint(aValue)
	return replacetext(aValue, character 2 of (2 / 3 as string), ".")
end inPoint

on doRound(aValue, Deci)
	-- 	set aValue to inDeci(aValue)
	set i to 10 ^ Deci
	return (((aValue * i) + 0.5) div 1) / i
end doRound

on inNewdegreees(aValue, aPlus)
	if aPlus = "" then return aValue
	set lValue to splittext(aValue, ": ")
	set lPlus to splittext(aPlus, " ")
	set aPlus to item 1 of lPlus
	if item 2 of lPlus = "S" or item 2 of lPlus = "W" then
		set aPlus to "-" & aPlus
	end if
	return item 1 of lValue & ": " & aPlus & " (" & item 2 of lValue & ")"
end inNewdegreees

on splittext(aStr, theDelimiter)
	set oldDelimiters to AppleScript's text item delimiters
	set AppleScript's text item delimiters to theDelimiter
	set theArray to every text item of aStr
	set AppleScript's text item delimiters to oldDelimiters
	return theArray
end splittext

on replacetext(aStr, oldString, newString)
	log oldString
	log aStr
	set oldDelimiters to AppleScript's text item delimiters
	set AppleScript's text item delimiters to oldString
	set theArray to every text item of (aStr as text)
	set AppleScript's text item delimiters to newString
	set newStr to theArray as text
	set AppleScript's text item delimiters to oldDelimiters
	return newStr
end replacetext

on trim(someText)
	repeat until someText does not start with " "
		set someText to text 2 thru -1 of someText
	end repeat

	repeat until someText does not end with " "
		set someText to text 1 thru -2 of someText
	end repeat

	return someText
end trim
Leave the first comment

Show ExifData of master image

This is a small applescript to show the exif data of the master image, not the exif data, stored in Aperture. This is the long version, it shows all exif data as a list and as atext file as needed. You have to install Exiftool to use the scripts. In the script there are other goodies like text functions.


on run
	set output to return
	tell application "Aperture"
		set imageSel to (get selection)
	end tell
	if imageSel is {} then
		display dialog "Please select an image in Aperture" with title "Exif-Data" buttons {"Okay"}
		return
	else
		--		repeat with i from 1 to count of imageSel
		set p to item 1 of imageSel -- item i
		set aPath to getPath(p)
		--		set output to output & aPath & return
		set output to GetApertureGPS(p)
		set output to output & GetExifTool(aPath)
		--		end repeat
	end if
	choose from list output with title "List Exif Metadata" with prompt "Picture:" & return & aPath OK button name "Show selected (or nothing)" cancel button name "Show all" with multiple selections allowed and empty selection allowed
	if the result is not {} then
		if the result is not false then
			set output to result
		end if
		tell application "TextEdit"
			activate
			set NewDoc to make new document
			set text of NewDoc to my jointext(output, return)
		end tell
	end if
end run

on GetExifTool(myPath)
	set exiftool_args to "-g1 -S "
	set the_md to "--- GPS ---" & return & "No Data found!" & return & ""
	set tLat to ""
	set tLong to ""
	try
		set the_md to do shell script "/usr/bin/exiftool " & exiftool_args & " " & myPath & " | grep GPS"
		set tLat to do shell script "/usr/bin/exiftool -c \"%.8f\" " & exiftool_args & " " & myPath & " | grep GPSLatitude: | sed s/GPSLatitude:\\ //"
		set tLong to do shell script "/usr/bin/exiftool -c \"%.8f\" " & exiftool_args & " " & myPath & " | grep GPSLongitude: | sed s/GPSLongitude:\\ //"
	end try
	set the_md1 to ""
	try
		set the_md1 to do shell script "/usr/bin/exiftool " & exiftool_args & " " & myPath & " | grep -v GPS"
	end try
	set textList to {}
	set textList to (splittext(the_md, return))
	repeat with i from 1 to count textList
		set p to item i of textList as string
		if (p contains "GPSLongitude:") then
			set item i of textList to inNewdegreees(p, tLong)
		end if
		if (p contains "GPSLatitude:") then
			set item i of textList to inNewdegreees(p, tLat)
		end if
	end repeat
	set textList to textList & (splittext(the_md1, return))
	return textList

end GetExifTool

on GetApertureGPS(aPic)
	set aLatitude to "no Data"
	set aLongitude to "no Data"
	set aAltitude to "no Data"
	set aGPSVersion to "no Data"
	tell application "Aperture"
		tell aPic
			try
				set aLatitude to (get value of EXIF tag "Latitude")
				set aLongitude to (get value of EXIF tag "Longitude")
				set aAltitude to (get value of EXIF tag "Altitude")
				set aGPSVersion to (get value of EXIF tag "GPSVersion")
			end try
		end tell
	end tell
	set AppleScript's text item delimiters to ""
	if aLongitude is not equal to "no Data" then
		set aLongitude to aLongitude & " (" & my inMinutes(aLongitude, false) & ")" as text
	end if
	if aLatitude is not equal to "no Data" then
		set aLatitude to aLatitude & " (" & my inMinutes(aLatitude, true) & ")" as text
	end if
	return {"--- Aperture ---", "Latitude: " & aLatitude, "Longitude: " & aLongitude, "Altitude: " & aAltitude, "GPSVersion: " & aGPSVersion, " "}
end GetApertureGPS

on getPath(aItem)
	tell application "Aperture"
		tell library 1
			tell aItem
				set ImpGroup to (get value of other tag "ImportGroup")
				set MasterPath to my GetMasterPath(ImpGroup)
				set MasterFile to (get value of other tag "FileName")
			end tell
		end tell
	end tell
	set MasterPath to my getLibPath() & MasterPath
	set aPath to quoted form of (MasterPath & MasterFile)
	return aPath
end getPath

on GetMasterPath(aStr)
	set tid to AppleScript's text item delimiters
	set AppleScript's text item delimiters to "-"
	set aYear to text item 1 of aStr
	set aMonth to text item 2 of aStr
	set aRest to text item 3 of aStr
	set AppleScript's text item delimiters to " @ "
	set aDay to text item 1 of aRest
	set aRest to text item 2 of aRest
	set AppleScript's text item delimiters to ":"
	set anHour to text item 1 of aRest
	set aMinute to text item 2 of aRest
	set aRest to text item 3 of aRest
	set AppleScript's text item delimiters to " "
	set aSecond to text item 1 of aRest
	set AmPm to text item 2 of aRest
	if AmPm is equal to "PM" then
		set anHour to anHour + 12
	end if
	set AppleScript's text item delimiters to "/"
	set aRest to {"", "Masters", aYear, aMonth, aDay, aYear & aMonth & aDay & "-" & anHour & aMinute & aSecond, ""} as text
	set AppleScript's text item delimiters to tid
	return aRest
end GetMasterPath

on getLibPath()
	tell application "System Events" to set p_libPath to value of property list item "LibraryPath" of property list file ((path to preferences as Unicode text) & "com.apple.aperture.plist")

	if ((offset of "~" in p_libPath) is not 0) then
		set p_script to "/bin/echo $HOME"
		set p_homePath to (do shell script p_script)

		set p_offset to offset of "~" in p_libPath
		set p_path to text (p_offset + 1) thru -1 of p_libPath

		set g_libPath to p_homePath & p_path
		return g_libPath
	else
		return p_libPath
	end if

end getLibPath

on inDeci(aValue)
	return replacetext(aValue, ".", (character 2 of (2 / 3 as string)))
end inDeci

on inMinutes(aValue, Lat)
	set aValue to inDeci(aValue)
	set degree to aValue
	if degree < 1 then
		set degree to degree * -1.0
		if Lat then
			set EWNS to "S"
		else
			set EWNS to "W"
		end if
	else
		if Lat then
			set EWNS to "N"
		else
			set EWNS to "E"
		end if
	end if
	set minute to (degree mod 1) * 60
	set degree to degree div 1
	set second to (minute mod 1) * 60
	set second to (doRound(second, 2))
	set second to my inPoint(second)
	set minute to minute div 1
	return degree & " deg " & minute & "' " & second & "\" " & EWNS
end inMinutes

on inPoint(aValue)
	return replacetext(aValue, character 2 of (2 / 3 as string), ".")
end inPoint

on doRound(aValue, Deci)
	-- 	set aValue to inDeci(aValue)
	set i to 10 ^ Deci
	return (((aValue * i) + 0.5) div 1) / i
end doRound

on inNewdegreees(aValue, aPlus)
	if aPlus = "" then return aValue
	set lValue to splittext(aValue, ": ")
	set lPlus to splittext(aPlus, " ")
	set aPlus to item 1 of lPlus
	if item 2 of lPlus = "S" or item 2 of lPlus = "W" then
		set aPlus to "-" & aPlus
	end if
	return item 1 of lValue & ": " & aPlus & " (" & item 2 of lValue & ")"
end inNewdegreees

on splittext(aStr, theDelimiter)
	set oldDelimiters to AppleScript's text item delimiters
	set AppleScript's text item delimiters to theDelimiter
	set theArray to every text item of aStr
	set AppleScript's text item delimiters to oldDelimiters
	return theArray
end splittext

on jointext(aList, theDelimiter)
	set oldDelimiters to AppleScript's text item delimiters
	set AppleScript's text item delimiters to theDelimiter
	set theArray to aList as text
	set AppleScript's text item delimiters to oldDelimiters
	return theArray
end jointext

on replacetext(aStr, oldString, newString)
	set oldDelimiters to AppleScript's text item delimiters
	set AppleScript's text item delimiters to oldString
	set theArray to every text item of (aStr as text)
	set AppleScript's text item delimiters to newString
	set newStr to theArray as text
	set AppleScript's text item delimiters to oldDelimiters
	return newStr
end replacetext

on trim(someText)
	repeat until someText does not start with " "
		set someText to text 2 thru -1 of someText
	end repeat

	repeat until someText does not end with " "
		set someText to text 1 thru -2 of someText
	end repeat

	return someText
end trim
One comment so far, add another

The same script without sqlite3


	#!/bin/bash

	PREFERENCE=""
	LIBRARY=""
	PLIST=""

	function setPreference {
		# $1 key $2 Preference file
		PREFERENCE=$(osascript \
			-e 'tell application "System Events"'\
			-e "return value of property list item \"$1\" of ¬
			property list file ((path to preferences as Unicode text) & \"$2\")" \
			-e 'end tell')
		if [ ${PREFERENCE:0:1} = "~" ] ; then
			PREFERENCE="$HOME${PREFERENCE:1}"
		fi
	}

	function setPLIST {
		# $1 key $2 File
		PLIST=$(osascript \
			-e 'tell application "System Events"'\
			-e "return value of property list item \"$1\" of ¬
			property list file (\"$2\")" \
			-e 'end tell')
	}

	function workID {
	ID=$(echo $1 | awk -F " " '{print $1}')
	theDate=$(echo $1 | awk -F " " '{print $2}')
	theTime=$(echo $1 | awk -F " " '{print $4}')
	theAMPM=$(echo $1 | awk -F " " '{print $5}')
	theYear=$(echo $theDate | awk -F "-" '{print $1}')
	theMonth=$(echo $theDate | awk -F "-" '{print $2}')
	theDay=$(echo $theDate | awk -F "-" '{print $3}')
	theHour=$(echo $theTime | awk -F ":" '{print $1}')
	theMinute=$(echo $theTime | awk -F ":" '{print $2}')
	theSecond=$(echo $theTime | awk -F ":" '{print $3}')
	if [ "$theAMPM" = "PM" ] ; then
	((theHour+=12))
	fi
	thePath="$PREFERENCE/Database/Versions/$theYear/$theMonth/$theDay/$theYear$theMonth$theDay"
	thePath="$thePath-$theHour$theMinute$theSecond"
	aFile=$(grep -lir $ID "$thePath"/*/Version-*.apversion)
	theDir=$(dirname $aFile)
	theFile=$(basename $aFile)
	setPLIST "uuid" "$theDir/Master.apmaster"
	uuid=$PLIST
	setPLIST "fileIsReference" "$theDir/Master.apmaster"
	isRef=$PLIST
	setPLIST "imagePath" "$theDir/Master.apmaster"
	imagePath=$PLIST
	setPLIST "name" "$theDir/Master.apmaster"
	name=$PLIST
	if [ $isRef = "false" ] ; then
		imagePath="$LIBRARY/Master/$imagePath"
	else
		imagePath="/$imagePath"
	fi
	echo "Version: '$theFile'"
	echo "Version ID: $ID"
	echo "Version path: '$theDir'"
	echo "Master name: '$name'"
	echo "File referenced: $isRef"
	echo "Master path: '$imagePath'"
	echo "Master ID: $uuid"
	echo $'\n'
	}

	setPreference "LibraryPath" "com.apple.Aperture.plist"
	LIBRARY="$PREFERENCE"

	theList=$(osascript \
		-e 'tell application "Aperture"' \
		-e 'set theList to "" ' \
		-e 'set imageSel to (get selection)' \
		-e 'if imageSel is {} then' \
		-e '   return ""' \
		-e 'else' \
		-e '   repeat with i from 1 to count of imageSel' \
		-e '      tell item i of imageSel' \
		-e '      set thePath to (get value of other tag "ImportGroup")' \
		-e '      set theID to (get id as rich text)' \
		-e '      set theList to theList &  theID & " " & thePath & return' \
		-e '   end tell' \
		-e '   end repeat' \
		-e '   return theList ' \
		-e 'end if' \
		-e 'end tell'  )

	if [ -z "$theList" ] ; then
		echo "No picture selected, Cancel"
		exit
	else
		oldIFS=$IFS
		IFS=$'\r\n'
		for ID in $theList ;do
		workID $ID
		done
		IFS=$oldIFS
	fi
	exit 0
Leave the first comment

Database copy

You don’t have to copy the Database every time you start the script.

Here is a solution to fasten the script:


if [ -n “$1” ] ; then # to force the copy give a parameter like 1
    rm $DB 2>/dev/null
fi
if [ -e “$DB” ]; then # the database exists ??
    echo “Database copy "$LIBRARY/Database/Library.apdb" exists.”
else
    echo “Copy "$LIBRARY/Database/Library.apdb" to "$DB".”
    cp  “$LIBRARY/Database/Library.apdb” “$DB”
fi
Leave the first comment