String concatenation is quite easy in AppleScript because you only need the ampersand between two strings (or variable holding the string). So you example would look like this.
There is also a begins with and ends with operator that works for lists and strings.
set outputFile to choose file name with prompt "Set file name and location of the reduced file:"
if outputFile does not ends with ".ps" then set outputFile to outputFile & ".ps"
--now outputFile always ends with .ps
Hi DJ. Don’t you have to convert outputFile to text first?
set outputFile to choose file name with prompt "Set file name and location of the reduced file:"
set thePath to outputFile as text
if thePath does not end with ".ps" then
set thePath to thePath & ".ps"
end if
return thePath
Otherwise you would get {file “Mac OS X:Users:DJ:test”, “.ps”}
Correct! I haven’t tested the code but choose file names doesn’t return a string so you need to coerce it first.
set outputFile to (choose file name with prompt "Set file name and location of the reduced file:") as string
if outputFile does not end with ".ps" then set outputFile to outputFile & ".txt"
--now outputFile always ends with .ps
The first part of the script os a dialogue asking for a file to resize, the next is what was discussed above. Choosing a filename and location for the resulting file.
What if I want to pass the path from the user selected file on to the default path in the save as dialogue?
This is what I have at the moment:
# Choose Postscript file to resize
set inputFile to (choose file with prompt "Select a Postscript file to resize:" of type {"ps"})
# Get proper UNIX path to Postscript file
set p_inputFile to POSIX path of inputFile
# Choose file name for reduced postscript file and force a .ps file extension
set outputFile to (choose file name with prompt "Set file name and location of the reduced file:" default name "reduced_file.ps")
set outputFile to outputFile as text
if outputFile does not end with ".ps" then
set outputFile to outputFile & ".ps"
end if
# Get proper UNIX path to reduced Postscript file
set p_outputFile to POSIX path of outputFile
Right now p_inputFile is returning something like:
/Users/UserName/Desktop/filename.ps
How would I strip the filename.ps portion of the variable and use it as the default path for the outputFile dialog?
set inputFile to (choose file with prompt "Select a Postscript file to resize:" of type {"ps"})
tell application "System Events" to set fileName to name of inputFile
# Get proper UNIX path to Postscript file
set p_inputFile to POSIX path of inputFile
# Choose file name for reduced postscript file and force a .ps file extension
set outputFile to (choose file name with prompt "Set file name and location of the reduced file:" default name "reduced_" & fileName)
set outputFile to outputFile as text
if outputFile does not end with ".ps" then
set outputFile to outputFile & ".ps"
end if
# Get proper UNIX path to reduced Postscript file
set p_outputFile to POSIX path of outputFile