AppleScript do shell script + paramêtres

daffyb

-Duck Warrior-
Modérateur
Club iGen
18 Octobre 2001
14 574
2 002
Angoulême
Bonjour,
C'est la première fois que je poste dans cet endroit du forum :D
J'ai une question certaiement très simple, mais bon, il faut bien débuter.
Donc, je débute avec un script de dossier en modifiant le script existant de convesion automatique d'image en JPEG pour faire une conversion d'un fichier AIFF en MP3.
Ma grosse question est comment fait-on pour passer des paramêtres à un script ?
Voici un extrait de mon script
Bloc de code:
tell application "Terminal"
[indent]do shell script with command "/sw/bin/lame"
[/indent] end tell
Le truc, c'est que je voudrais passer des paramêtres à ma commande lame et le paramêtre en question, est le fichié glissé sur le dossier scripté. Comment que je fais ?
Merci
Bertrand
 
Comme j'ai un peu avancé, maintenant, j'arrive à passer mes paramètres (mais pas totalement)
voici mon code :
Bloc de code:
property done_foldername : "MP3 Sound Files"
property originals_foldername : "Original Sound Files"
property newimage_extension : "jpg"
property type_list : {"AIF", "AIFF"}
property extension_list : {"aif", "aiff"}


on adding folder items to this_folder after receiving these_items
	tell application "Finder"
		if not (exists folder done_foldername of this_folder) then
			make new folder at this_folder with properties {name:done_foldername}
		end if
		set the results_folder to (folder done_foldername of this_folder) as alias
		if not (exists folder originals_foldername of this_folder) then
			make new folder at this_folder with properties {name:originals_foldername}
			set current view of container window of this_folder to list view
		end if
		set the originals_folder to folder originals_foldername of this_folder
	end tell
	try
		repeat with i from 1 to number of items in these_items
			set this_item to item i of these_items
			set the item_info to the info for this_item
			if (alias of the item_info is false and the file type of the item_info is in the type_list) or (the name extension of the item_info is in the extension_list) then
				tell application "Finder"
					my resolve_conflicts(this_item, originals_folder, "")
					set the new_name to my resolve_conflicts(this_item, results_folder, newimage_extension)
					set the source_file to (move this_item to the originals_folder with replacing) as alias
				end tell
				process_item(source_file, new_name, results_folder)
			end if
		end repeat
	on error error_message number error_number
		if the error_number is not -128 then
			tell application "Finder"
				activate
				display dialog error_message buttons {"Cancel"} default button 1 giving up after 120
			end tell
		end if
	end try
end adding folder items to

on resolve_conflicts(this_item, target_folder, new_extension)
	tell application "Finder"
		set the file_name to the name of this_item
		set file_extension to the name extension of this_item
		if the file_extension is "" then
			set the trimmed_name to the file_name
		else
			set the trimmed_name to text 1 thru -((length of file_extension) + 2) of the file_name
		end if
		if the new_extension is "" then
			set target_name to file_name
			set target_extension to file_extension
		else
			set target_extension to new_extension
			set target_name to (the trimmed_name & "." & target_extension) as string
		end if
		if (exists document file target_name of target_folder) then
			set the name_increment to 1
			repeat
				set the new_name to (the trimmed_name & "." & (name_increment as string) & "." & target_extension) as string
				if not (exists document file new_name of the target_folder) then
					-- rename to conflicting file
					set the name of document file target_name of the target_folder to the new_name
					exit repeat
				else
					set the name_increment to the name_increment + 1
				end if
			end repeat
		end if
	end tell
	return the target_name
end resolve_conflicts

-- this sub-routine processes files 
on process_item(source_file, new_name, results_folder)
	-- NOTE that the variable this_item is a file reference in alias format 
	-- FILE PROCESSING STATEMENTS GOES HERE 
	try
		-- the target path is the destination folder and the new file name
		set the target_path to ((results_folder as string) & new_name) as string
		with timeout of 900 seconds
			tell application "Terminal"
				do script with command "/sw/bin/lame " & source_file & results_folder & " / " & "new_name"
			end tell
		end timeout
	on error error_message
		tell application "Finder"
			activate
			display dialog error_message buttons {"Cancel"} default button 1 giving up after 120
		end tell
	end try
end process_item
L'erreur vient du fait que les chemins des fichiers sont de ce type et donc pas très "unix"
Bloc de code:
Little:Users:bertrand:Desktop:aiff2mp3:Original Sound Files:Once upon a time.AIFF
Comment dois-je faire pour avoir des / à la place des : ? et pouvoir saisir des " dans mes expression ?
Merci :zen:
 
Didier Guillion a dit:
Bonsoir,

Réponse rapide:

Il faut convertir des chemins Mac OS 8-9 en chemln UNIX en utilisant "as POSIX".

Fait une petite recherche sur le forum Apple a ce sujet, et si le probleme perdure, n'hesite pas a reposer la question.

Cordialement
Merci Didier :up:
J'arrive à mes fin, mais (car il y a un mais) je n'arrive pas à lancer cela sans que le terminal se lance en utilisant la commande
do shell script
voici mon bout de code :
Bloc de code:
set source_file to the POSIX path of source_file
set results_folder to the POSIX path of results_folder
   tell application "Terminal"
   do script with command "/sw/bin/lame " & "'" & source_file & "' '" & results_folder & new_name & "'"
J'ai encore besoin d'un petit coup de main. Merci :)
 
:up: :D
ayé, j'ai réussi !!!
Je mets donc ici ce script de dossier. :love:
 
Salut,

Bon, je ne sais pas pourquoi, je n'ai pas réussi à télécharger ton script, ça s'obstine à vouloir télécharger la page "attachement.php" ce qui est assez idiot... enfin bon...

Je suis potentiellement très intéressé par ton script. J'utilise le logiciel "drop jpeg" qui permet de convertir à peu près n'importe quoi en image .jpg, et je cherche depuis très longtemps l'équivalent pour convertir à peu près n'importe quoi en .mp3. Dans le genre d'une petite application qu'on pourrait garder tout le temps dans le dock pour glisser dessus les fichiers qu'on veut convertir...

Voilà pourquoi ton programme m'intéresse... Je suis incapable de le faire moi même c'est pourquoi je ne peux que te donner tous mes encouragements...

Seb
 
un simple clip sur le lien permet de télécharger le script.....
Je ne comprends pas ton soucis :(
 
daffyb a dit:
un simple clip sur le lien permet de télécharger le script.....
Je ne comprends pas ton soucis :(

Va comprendre... je n'en sais rien... safari persistait à télécharger "attachement.php" ce qui ne m'avançait pas à grand chose...
Aujourd'hui ça a marché...

Par contre, je ne suis pas geek pour un sous et du coup je ne sais absolument pas comment utiliser ton script... :rose:

Seb