GUI scripting and selection of files

good afternoon everybody,

Here is what I want to realize:

  1. I want to geotag some of my photos. I am usins gpsbabel to convert the log file to a gpx file. ← this works fine with a shell script.
  2. The converted file should be loaded into gpsphotolinker (this app does not support AS or Shellscripts so the only way is GUI scripting)
  3. I am able to load the app, call the dialogue (the one that should load the converted gpx file) BUT then i am stuck. I am not able to select the file automaticlly…
  4. after lloading the gpx file I want to call the “load photos” button. ← this works fine with GUI
  5. a specified folder, containing the photos should be selected and loaded. BUT again. I am stuck at this selection part.

above you will find my code and also some pictures of the gui if it is helpful. THX for all tipps and tricks to get this working :wink:


please see below...

a picture of the app: http://img504.imageshack.us/img504/8158/bild2im9.png
a picture of the “open gpx file” dialogue: http://img504.imageshack.us/img504/5488/bild1wf7.png
a picture of the “open photo folder” dialouge: http://img176.imageshack.us/img176/4742/bild3ma2.png

THX again for any solutions :wink:

goeste

OK!

DONE:

every body who is interested here is the code that works for me :wink:

please see below...

selecting datafile, convert data file to gpx file, open gpsphotolinker, switch to batch mode, select gpx file, select photo folder, click process batch tagging(need to be done manually) :wink:

there is a new version of my script. But I think there is still work to improve the script. Please Feel free to adapt and optimize the script so that it can be used on any macihen and not only mine (according to the hardcoded folders and so on). BTW:

I DID NOT WRITE GPSBABEL OR GPSPHOTOLINKER I ONLY USE IT AND I DO NOT CLAIM ANY RIGHTS ON IT OR THE SCRIPT. IT IS JUST AN AUTOMATED WORKFLOW TO MAKE MY LIFE A LITTLE EASIER :wink:


please see below

maybe an option to implement is ask to read several log files… so that the “convert” is running as log as there are files to convert. GPSPhotoLinker also has to import these files first before loading the pictures.

Lets see If someboy has a clue. I am just a basic-non-pro-2cents-when-ever-I-have-time-wannabe coder…

ok, here is a question that i do not get to work:

How can i select multiple LOG files and let these processed by the convert-part? and after that, how can i rename the output of the convert-part (eg. and sequenced number ad the end?)??

thx in advance

does nobody really have a hint for me? please?

I think I have one :wink:


set logFolder to choose folder with prompt "Bitte wähle einen Ordner mit LOG Dateien aus"
set photofolder to choose folder with prompt "Bitte wähle das Verzeichnis mit den zu taggenden Fotos aus"
set output_folder to (path to documents folder as text) & "gps_backup_files:"
set filename to do shell script "/bin/date +%Y%m%d" & "track_log.gpx"
set gpxfile to POSIX path of output_folder & filename

tell application "Finder" to set logFiles to files of logFolder -- whose name extension is ".log"
repeat with oneFile in logFiles
	convert(oneFile as alias, gpxfile)
	-- delay 5
	geotag(gpxfile, photofolder)
end repeat

the date_format() handler is not needed any more.
you can use the commented out whose name extension. if you want to filter the log files.
The delay is actually not needed, too. If the script passes this line, all further actions are already done.

PS: Ich bin gerade in der Nähe von Düsseldorf :wink:

first of all thx:) I’ll give it a try when I’m back home after work.
Does this not collidate with the posix handler within ite convert script?

nice:) z.Z. bin ich aber nicht in HOnnef sondern in Madrid:)

No, usually the script continues after any shell script line when the shell execution has finished

ok… went home during lunch break. every thing works fine right now. thx very much for your help.

One more thing: how can I cut off the last 4 characters of a filename (eg the extension)?

lg and greetings

goeste


set theText to text 1 thru -5 of theOriginalText

ok. thx for the cutting-text-part craig.

the codes looks like this right now:

please see below...

But the last part (the "lesen aller .gpx files) does not work AS tells me always that it is not possible to read from the DIR (

any hint on this ?

btw. I still have to comment and split the geotag-part.

thank you very much and sorry for so much questions :slight_smile:

goeste

you try to get files from a literal string, not from a folder


.
tell application "Finder" to set gpxFiles to files of folder logfolder2 -- whose name contains ".gpx" --lesen aller .gpx files
.

note: it’s probably faster to check the name extension (whose name extension is “gpx”)

YOU ARE THE BEST…I LOVE THIS PLACE :wink:

thx very much for all your help Stefan & Craig. Now it works just like I want it and it saves me a lot of time to geotag my photos :wink:

here is the final script (but I think there is still sth. to improve,shorten, etc):

set logFolder to choose folder with prompt "Bitte wähle einen Ordner mit LOG Dateien aus"
set logFolderOut to (path to documents folder as text) & "gps_backup_files:"
set logfolder2 to "leopard:users:goeste:documents:gps_backup_files:"
set picFolder to choose folder with prompt "Bitte wähle die zu taggenden Fotos aus"
set gpxDate to do shell script "/bin/date +%Y%m%d" --datum erzeugen

on convert(input, output) --log zu gpx konvertierung
	set program_path to path to me --pfad zu gpsbabel
	tell application "Finder" to set forig to name of input --altendateinamen merken
	set fDate to do shell script "/bin/date +%Y%m%d" & "-" --datumsdatei erzeugen
	set fname to output & fDate & forig --dateinamen setzen
	set gpxfile to text 1 thru -5 of fname --dateiendung entfernen
	do shell script POSIX path of program_path & "Contents/Resources/gpsbabel -t -i NMEA -f " & POSIX path of input & " -o GPX -F " & POSIX path of gpxfile --konvertierung mit gpsbabel
	do shell script "mv " & POSIX path of gpxfile & " " & POSIX path of gpxfile & ".gpx" --dateiendung gpx setzen
end convert

on geotag(gpx)
	activate application "GPSPhotoLinker"
	tell application "System Events"
		tell process "GPSPhotoLinker"
			click radio button 3 of tab group 1 of window "GPSPhotoLinker" --batch-modus aktivieren
			delay 1
			click menu item "Load Tracks From File." of menu 1 of menu bar item "Tracks" of menu bar 1 --load tracks klicken im menü
			delay 0.5
			keystroke "/" using {control down} --gehe zu.. öffnen
			tell window 1
				tell sheet 1
					set value of text field 1 to gpx --log file angeben als unix pfad
					click button 1
				end tell
				click button 1
			end tell
			delay 0.5
			click button 4 of window 1
			delay 3
			--hier könne es weiter gehen mit der Automatisierung...
		end tell
	end tell
end geotag

on loadphotos(pfolder)
	activate application "GPSPhotoLinker"
	tell application "System Events"
		tell process "GPSPhotoLinker"
			click menu item "Load Photos." of menu 1 of menu bar item "Photos" of menu bar 1 --load photos klicken
			delay 0.5
			keystroke "/" using {control down} --gehe zu.. öffnen
			--lade Bilderverzeichnis
			tell window 1
				tell sheet 1
					tell sheet 1
						set value of text field 1 to POSIX path of pfolder --bilder folder angeben als unix pfad
						click button 1
					end tell
					click button 1
				end tell
			end tell
		end tell
	end tell
end loadphotos

--hier gehen die abläufe los
tell application "Finder" to set logFiles to files of logFolder whose name contains ".log" --lesen aller .log files
repeat with onefile in logFiles
	convert(onefile as alias, logFolderOut) --konvertieren und bennen der logfiles
end repeat
tell application "Finder" to set gpxFiles to files of folder logfolder2 whose name contains gpxDate and name contains ".gpx" --lesen aller .gpx files mit aktuellem datum (verhinter doppel import) 
repeat with gpxfile in gpxFiles
	geotag(gpxfile as alias) --einlesen der .gpx files
end repeat
loadphotos(picFolder) --einlesen des bilder verzeichnises

thx again and keep up your work… I’ve learned a lot during this few days :slight_smile:

goeste

two suggestions:

¢ logFolder and logFolderOut point to the same path. Certainly only one of them is necessary.
¢ It’s strongly recommended to escape POSIX path always with quoted form of, because the path could contain space characters, which are recognized as parameter delimiters by the shell

for example

do shell script quoted form of (POSIX path of program_path & "Contents/Resources/gpsbabel") & " -t -i NMEA -f " & quoted form of POSIX path of input & " -o GPX -F " & quoted form of POSIX path of gpxfile --konvertierung mit gpsbabel
   do shell script "mv " & quoted form of POSIX path of gpxfile & " " & quoted form of (POSIX path of gpxfile & ".gpx") --dateiendung gpx setzen

Consider that after quoted form of the whole path including all concatenations must be within parentheses

Thx Stefan, I ran into this trouble right now, after renaming the .app (name with spaces).
I also built in a create_folder if the outputfolder for the gpx files does not exist.
Thx again