Passing a list of chosen folders as a parameter

Hello,

I’ve looked everywhere and haven’t found this. I have a script that starts with a choose folder with prompt multiple selections allowed. The script parses the file names which contain a revision number and then increments that number up by one. It then sets the filename to the existing name at the new revision. I want to pass all my chosen folders to another Applescript that will then take them and open Photoshop create a layer and add the new revision to the Photoshop file (I have this script already and it works but requires you to choose folders with prompt). Basically, what I have are several Applescripts that process filenames and add text to documents and I want to be able to run these scripts using the same choosen folders. In the end I would like to

  1. pick a set of folders
  2. uprev the name of the files in those folders --have that script
  3. pass the folders as a parameter to a script that will have Photoshop add the new revision --have this script
  4. pass the folders as a parameter to a script that makes a pdf out of all the individual Photoshop files, names it and places it back in the original art folder --have this script

The idea is to pick one set of multiple folders and then pass them to each script rather that having to choose them repeatedly in each script. I’m not terribly experienced at AS, so I don’t even know what shell scripting is yet. I’m looking for a way to do this with Applescript alone.

Am I looking to do something that isn’t possible? I have passed text to a separate script, but I can’t get this to work.

Regards, :cool:

  • Zoar

Perhaps a simple example will help:

First script, saved with a name:

on run {mult, myList} -- the list of parameters following 'run'
	set ans to {}
	repeat with I in myList
		set end of ans to mult * I
	end repeat
	return ans
end run

The calling script:

set newList to run script (path to first script as alias here) with parameters {3, {1, 2, 3, 4}}
--> {3, 6, 9, 12}

Judging from what you’ve outlined, you’d call the script that gets the folders and fixes their names in the script that calls PS.

Hello Adam,

Thanks for the prompt reply. What I really want to do is something like this

set myFolder to choose folder
set called_script to "Macintosh HD:PATH TO MY SCRIPT:get_files.scpt"-->THIS WILL RETURN EVERY FILE
run script alias called_script with parameters {myFolder}

set theFileList to the result --> list of the files as complete paths to the files this works

set called_script to "Macintosh HD:PATH TO MY SCRIPT:addTheRev-c.scpt"
run script alias called_script with parameters {theFileList} -- I want to pass the list of files this doesn't work it won't see it as text
set fileNames to the result
--return theOutput

All the parameters that I want to pass are variables. In your sample you gave parameters that were the actual values or the list actually inputted. The second called script is going to parse the file names and get the revision number and add tell Photoshop to open each file in theFileList and place that number on the page then save it with replacing.

in addTheRev-c script I want to repeat with i from 1 to count(theFileList), but it doesn’t seem possible to pass a list. Maybe

run script alias called_script with parameters {theFileList}as string

Then I’d have to coerce theFileList as string back into a list (as list) in the receiving program?

Regards,

  • Zoar

Have you tried it? When I run these they do the job.

Stored script:

on run {mult, myList} -- the string of parameters following 'run'
	set tid to AppleScript's text item delimiters
	set AppleScript's text item delimiters to ","
	set tParts to (text items of myList)
	set AppleScript's text item delimiters to tid
	set ans to {}
	repeat with I in tParts
		set end of ans to mult * I
	end repeat
	return ans
end run

Calling it with this, where all parameters are variables:

set mult to text returned of (display dialog "Enter the multiplier" default answer "2") as integer
set called to choose file
set tList to text returned of (display dialog "Enter 4 numbers separated by commas, no spaces" default answer "1,3,5,7")
set newList to run script called with parameters {mult, tList}
--> {2, 6, 10, 14}

Perhaps you could be more specific about how your script is failing.

Hi Adam,

I got a message that it could not go after this identifier and this portion of the script was hi-lighted

on run script called with parameters {mult, tList}

.

Maybe I’m thick, but I don’t want to have to manually enter anything no prompts other than choosing the folders. All the actions (on run) would process the files and pass them to the next process on so on. I wanted to do away with constantly cutting and pasting large sections of scripts into other scripts. I’ve heard that is a bad practice, but I’m not finding any way that AS will pass the info. I got it to pass the chosen folder to a routine that created a list of files in that folder. I now want to be able to pull the revision number which is part of the file name description_indexNumber_revisionNumber.psd. I can see where some called scripts are going to need parameters such as {chosenFolder, myFileList, allRevNums} with all of these being lists.

Typically I would do that with set fileName to name of item i of myFileList (where myFileList is the result returned list from a called script, so far the only one that works) and that would return just the filename from the path. That isn’t even working.

Here’s a snippet dummied up of myFileList and it appears to be a valid list

{document file “123785_ID_01_A.psd” of folder “123785” of folder “DOCS” of folder " HD" of startup disk, document file “123785_ID_02_A.psd” of folder “123785” of folder “FINALS” of folder " HD" of startup disk}

" HD" folder starts with a space to force it to the top of my directory list. I don’t know if that’s an issue. It never has been before.

Thanks,

  • Zoar

Model: Mac G5
AppleScript: AppleScript 1.10.7
Browser: Safari 525.27.1
Operating System: Mac OS X (10.4)

We seem to be a bit at cross purposes here, Zoar. At one point you asserted that your script wouldn’t function with variables. I responded with a script that worked (at least for me) with variables as the parameters. That I used dialogs and choose file to illustrate that did not mean you had to.

If the file list you’ve developed is a list of text where I assume you used something like:

tell application "Finder" to set Flist to files of folder (chosen) as alias list

or perhaps if there were folders in the chosen folder and you wanted to dig down:

tell application "Finder" to set Flist to files of entire contents of folder (chosen) as alias list

and that Flist is what you want to pass.

Next, on receiving that file list, I’m assuming that the second script then operates on the aliases one at a time and that it is doing so on the same machine so that the paths are valid.

If this doesn’t help then I’ll have to see the relevant portions of the scripts being called. You can annonomize them.

I don’t think spaces matter in an HFS path (they do in a posix address where they must be escaped).

These are not valid paths. You need an HFS path.


eg.
Mac:yourName:desktop:file.txt

Get the file path as a string or an alias before adding it to your list.

And as Adam has said, before we can help any further we need to see your code.
That is much easier than us trying to guess what the problem is.