Zade
Zade

Reputation: 692

Convert AppleScript to one line

I'm using Mach Desktop to echo a script's results into a Desklet, so it has to be in this format:

echo 'tell application "iTunes" to return album of current track' | osascript

I have a single line in which to enter data, so the script needs to be one long string. It may be that the entire thing must be contained within one set of single quotes after echo, as follows:

echo '[entire script]' | osascript

How do I convert the AppleScript below to one line?

set some_file to "Macintosh HD:Users:Zade:Library:Application Support:Notational Data:Words.txt" as alias
set the_text to read some_file as string
set the text item delimiters of AppleScript to ", "
set the_lines to (every text item of the_text)
return some item of the_lines

Here is what I'm trying:

echo 'set some_file to "Macintosh HD:Users:Zade:Library:Application Support:Notational Data:Words.txt" as alias -e set the_text to read some_file as string -e set the text item delimiters of AppleScript to ", " -e set the_lines to (every text item of the_text) -e return some item of the_lines' | osascript

And that gives this error:

107:112: syntax error: A "set" can't go after this identifier. (-2740)

Upvotes: 1

Views: 1049

Answers (1)

fireshadow52
fireshadow52

Reputation: 6516

I suppose you could try out this script. I'm confused as to what you're actually trying to accomplish, though, so I apologize if this script is unsatisfactory.

echo 'set some_file to "~/Library/Application Support/Notational Data/Words.txt" as POSIX file as alias' -e 'set the_text to read some_file' -e 'set the text item delimeters of AppleScript to ","' -e 'set the lines to (every text item of the_text)' -e 'return the lines' | osascript

EDIT: @Zade That would be because Words.txt doesn't exist. Aliases only refer to existing files. Therefore, you must choose a file that exists. Here is an easy way to see what the correct syntax is for file references:

set some_file to (choose file)

You will notice that the file path is delimited by colons ( : ) rather than slashes. Having said this, choose a file that exists, and run your script with that file.

Upvotes: 1

Related Questions