How to insert a variable into a string using applescript

Q1:

"This is hello word" 
set var to "my"

I want to insert v into the string .The string will be "This is my hello word"

How could i do this with applescript?

Q2:

My script calls some shellscript files,where should i put these files if i export my script as a application,

Thanks a lot ,guys

Accepted Reply

I want to insert v into the string.

Strings are immutable in AppleScript, so you can’t change the string itself. Rather, you have to build a new string from the parts you need. For example:

set s to "Hello World"
set o to offset of " " in s
set s2 to (text 1 through o of s) & " Cruel " & (text o through -1 of s)
-- s2 is "Hello Cruel World"

If you do this a lot then you should create a function that’s specific to your needs

where should i put these files if i export my script as a application

The standard approach is to save your script as Script Bundle and then add any extra resources, like shell scripts, to your bundle’s contents (View > Show Bundle Contents).

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

Replies

I want to insert v into the string.

Strings are immutable in AppleScript, so you can’t change the string itself. Rather, you have to build a new string from the parts you need. For example:

set s to "Hello World"
set o to offset of " " in s
set s2 to (text 1 through o of s) & " Cruel " & (text o through -1 of s)
-- s2 is "Hello Cruel World"

If you do this a lot then you should create a function that’s specific to your needs

where should i put these files if i export my script as a application

The standard approach is to save your script as Script Bundle and then add any extra resources, like shell scripts, to your bundle’s contents (View > Show Bundle Contents).

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

Thank you a lot .😁