So basically I was messing around with AppleScript and created a variable based on the app's path and it always has a forward slash at the end that I don't want. See my other question for more info. Basically thePath is set to /Applications/MyEpicApp.app/ with that extra / I don't want.

What's the "opposite" of "sometext" & someVariable in AppleScript?

Many thanks in advance, I appreaciate every piece of information.

2 Answers 2


To have a portion of the string returned, the format would be:

set StringVariable2 to (characters n through n of StringVariable1) as string

n is the character number of the string starting at 1
as string is important or otherwise you get a list of single characters returned

Just make sure that whenever you parse any text, list or other item inside AppleScript to have text item delimiters at their default value (an empty list {}) unless you want to include those characters in the result as well.

In your example of removing the last character, it would be:

set StringVariable2 to (characters 1 through ((length of StringVariable1) - 1) of StringVariable1) as string
  • @Alex Zavatone, I removed your edit for two reasons... 1. This answer (and question for that matter) really has nothing to do with text item delimiters because by default it's already {} or "". 2. It was not changed to begin with and therefore no need to do anything with it and totally unnecessary for this answer! Nov 11, 2018 at 3:09
  • @user3439894 The answer has everything to do with the answer, because if the user has set different AppleScript text item delimiters then this will not work. It is required to set the item delimiters to what I mentioned or this will fail. My edit provided a complete solution. The above failed for me because the text item delimiters were not "". Nov 11, 2018 at 4:59
  • @user3439894 The reason I added this in the first place is that the provided solution did not work when I tested it. This was because I had been using different text item delimiters. My edits are the result of testing and verification. Nov 11, 2018 at 5:03
  • @Alex Zavatone, I must really side with user3439894 as the default is really an empty list and due to the fact, that the answer had been accepted more than 2 years back. While I agree that changing the text item delimiter may alter the result, it is generally a bad practice to change something and leave it changed for a prolonged time throughout your script and then “complain” that something does not work as advertised. Therefore, I would rather recommend to change the text item delimiter back as soon as you are finished with it in that section and set it again, if needed again.
    – Phoenix
    Nov 11, 2018 at 7:31
  • 1
    @AlexZavatone and as user3439894 and I already explained, the default is an empty list. It is generally bad practice to change it for a prolonged time as this will have negative impact on many things inside AppleScript. The AppleScript Language Guide explains how text item delimiters work and derived from that anyone can conclude that changing them for a prolonged time will bring unexpected behavior with it. I kindly ask you to not edit my answer since with good practical use of text item delimiters, it does not add any extra value to this answer.
    – Phoenix
    Nov 13, 2018 at 17:00

This statement uses AppleScript's negative-subscript feature to remove a trailing "/" if present:

if the_path ends with "/" then set the_path to text 1 thru -2 of the_path

This does nothing (no error is generated) if the_path contains "".

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .