Hello everyone,
I’m absolutely new to AppleScript but I’m trying to understand if AS can help me to develop a small and not-so-useful idea I have. Now with Automator available…maybe I’ll be able to create it
The first thing to understand is…
…is there a way to enter a word or small phrase in a dialog and let AS get all the single letters in it and “pass” them in some way as variables.
In example…the dialog appears, I write the world “hello”, AS extracts the letters “h”, “e”, “l”, “l” and “o”…and then with Automator (because I can’t handle AS too much) I’d tell what to do with those letters.
@ tampano:
kel’s and my script do almost exactly the same!
The only difference is that my script creates the variable directly without a temporary one
But the result is the same!
Now…the second phase is: how to “isolate” the results? Or better. How can I recall each of those letters as a single value?
In example: the result of the starting script is a list formatted this way (i can see in the result window on ScriptEditor:
{“h”, “e”, “l”, “l”, “o”}
Ok?
I’d like to have each single value, identifyable as each one.
If I want to tell Automator (always because now I can’t do it in AS ) “create (or choose) a document which name starts with the first value of the result”…how to do that? Now I have those values all in a a row, right?
The final result would be something like “choose a file which name starts with “h”, then another starting with “e””…etc
set thecharacterslist to get characters of text returned of (display dialog "gimme the phrase:" default answer "")
repeat with thechar in thecharacterslist
set thefile to choose file with prompt ("Choose a file which begins with a '" & thechar & "'")
end repeat
If you could tell us a bit more precise about what you want to do exactly - we could help you with better code (as we then know what it is for - and how to write it in the best way)!?
Example:
Do you want to display a dialog that tells the user to choose a file beginning with the desired character?
Or do you want Applescript (or Automator - how you call it) to find a file that begins with the desired character itself?
The idea is, from a given source folder or drive, the program would choose automatically the exact sequence of documents which names are starting with each letter of the string.
So:
a) the first phase of the script gets the string and identifies all the letters
b) at some point of the execution (even before “a)”, no matter) the user has to determine from where to get the documents
b1) (maybe filter only given kind of documents)
c) the second phase of the script choose the documents and organize them in some way (group in another folder, copy the documents elsewhere…something like that)
d)…not thought abot “d”
Being not a AS expert (neither a simple user) I think all the things could work with a combination of AS and Automator…maybe.
I haven’t embedded a kind filter but I think this is the raw structure:
set thecharacterslist to get characters of text returned of (display dialog "gimme the phrase:" default answer "")
set thefolder to choose folder with prompt "Choose folder to take the files from:"
set thefiles to list folder thefolder
repeat with thechar in thecharacterslist
set thefiltered to {}
repeat with i in thefiles
if i starts with thechar then set end of thefiltered to i
end repeat
--thefiltered is the list of file in "thefolder" (only files in first folder level!) that beginn with character "thechar"
--action would go here:
end repeat
Have fun!
Vince
Ps: Why do that with an Automator action?
Automator actions are nice if you want many actions that can follow in custom order.
But if you only want this to be done . why not just make an Applescript Application?
I don’t get the point why to make an action - sorry!
The reason is I’m completely blind about AS Simple. And I was looking for a way to use Automator without knowing too much about AS language of programming.
Maybe it’s better to explain my small idea.
I’d like a piece of software who asks me a small phrase and create an iTunes compilation of songs which name starts with every single letter of the given phrase.
So…I write “I love you” and the script/program/workflow/whateverelse scans my iTunes music library and creates a new playlist with, in this case, eight songs like:
In the summertime
Let it be
One
Vanity fair
Every breath you take
Yer blues
On my own
Under pressure
A simple and cool way to creat an “acronym” playlist to make cool gifts to friends. That’s all
set str to "I love you"
set playlistName to "new list"
tell application "iTunes"
set thePlaylist to make new playlist with properties {name:playlistName}
repeat with charRef in str
if charRef is in "abcdefghijklmnopqrstuvwxyz" then
duplicate (some track of playlist "library" whose name begins with charRef) to thePlaylist -- note: will raise error if no suitable track found
end if
end repeat
end tell