Nobody can answer this without your target application.
AppleScript is a kind of conversation with other application (target).
So, you have to tell with some application (Keynote? Microsoft PowerPoint? Adobe InDesign?).
And...the target application must placed at your machine. We can not compile (check syntax and translate into AppleEvents code) AppleScript without target application binary.
Post
Replies
Boosts
Views
Activity
I wrote an ebooks about Keynote, Pages and Numbers scripting. Text item manipulation is a very easy task for AppleScript.
https://piyomarusoft.booth.pm/items/4049167
Select like red colors text items on current slide on Keynote document
https://www.youtube.com/watch?v=3ykU_RQA-Cg
Mark strings sandwitched by start_string and end_string in current Keynote slide
https://www.youtube.com/watch?v=aIkQh7ho3WA
Compiling Keynote text item as "AppleScript" program and apply syntax colors demo AppleScript
https://www.youtube.com/watch?v=HXJGRBrUzyE
It is a very easy task for AppleScript (+Cocoa).
use AppleScript version "2.4"
use scripting additions
use framework "Foundation"
use framework "AppKit"
set aFolder to POSIX path of (choose folder with prompt "Select search target folder")
current application's NSWorkspace's sharedWorkspace()'s selectFile:(missing value) inFileViewerRootedAtPath:aFolder
set aResCode to current application's NSWorkspace's sharedWorkspace()'s showSearchResultsForQueryString:"ptw"
"myCount" is not variable. "myCount" is a string data.
tell application "Finder"
activate
set myCount to 6801 + (count (folders of folder "OZ" of disk "_NEW"))
make new folder at folder "OZ" of disk "_NEW" with properties {name:"temp"}
tell application "Finder" to open "_NEW:OZ:temp"
set name of folder "temp" of folder "OZ" of disk "_NEW" to myCount
set myName to text returned of (display dialog "Name:" default answer "Name")
set myTime to (do shell script "date +\"%D\"")
make new folder at folder (myCount as string) of folder "OZ" of disk "_NEW" with properties {name:"temp2"}
set name of folder "temp2" of folder (myCount as string) of folder "OZ" of disk "_NEW" to myTime
end tell
I wrote an ebook "AppleScript practical technics (1) GUI Scripting"(PDF 315pages).
This book include scripts to show each System Settings pane.
https://piyomarusoft.booth.pm/items/4230018
Off course, more easier books available. Basic technic books (1)...(29).
https://piyomarusoft.booth.pm/item_lists/rBkTpqJm
At first, execute other meaningless AppleScript to control other applications.
tell application "Microsoft Remote Desktop" to activate
tell me activate
Once, application control and authentication executed, your app is authenticated.
You can detect tcc status by using Objective-C program.
I built it as a Cocoa framework and call it from AppleScript application.
http://piyocast.com/as/archives/4819
You can write and compile (check syntax) then...
tell application "Photos"
import input into album "Cartoon" skip check duplicates true
end tell
This code is converted to this style
tell application "Photos"
import input into album "Cartoon" with skip check duplicates
end tell
Hmm.. something wrong with my post...
-- Created 2016-12-17 by Takaaki Naganoya
-- Updated 2023-03-06 by Takaaki Naganoya
-- 2016 Piyomaru Software
use AppleScript version "2.4"
use scripting additions
use framework "Foundation"
set aDevRes to getActiveNetworkInterfaceDeviceName() of me
--set aDevList to devName of (first item of aDevRes)
repeat with i in aDevRes
set aDev to devName of contents of i
log aDev
--http://superuser.com/questions/86956/release-renew-ip-address-via-terminal-in-os-x
do shell script ("ipconfig set " & quoted form of aDev & " DHCP") with administrator privileges
end repeat
--ifconfigからactiveなデバイス名だけをピックアップする
on getActiveNetworkInterfaceDeviceName()
set aRes to (do shell script "ifconfig")
set aList to paragraphs of aRes
set devNameList to {}
repeat with i in aList
set j to contents of i
set bRes to regexMatches(j, "^[^\\t]*") of me
if bRes is not equal to {{""}} then
set the end of devNameList to contents of item 1 of item 1 of bRes
end if
end repeat
--Parse ifconfig results by device name list
set curDelim to AppleScript's text item delimiters
set AppleScript's text item delimiters to devNameList --かなりトリッキー
set tmpList to text items of aRes
set AppleScript's text item delimiters to curDelim
--initialize
set bList to rest of tmpList --remove blank item at top
set aCount to 1
set aResList to current application's NSMutableArray's alloc()'s init()
repeat with i in bList
set aCon to contents of i
set aDat to contents of item aCount of devNameList
--Device Name
set aDevName to retStrFromTopToAstr(aDat, ":") of me
set bCon to paragraphs 2 thru -1 of aCon
set cCon to aDat & retDelimedText(bCon, return) of me
--Activeなdeviceを抽出するための条件付け
set activeF1 to cCon contains "status: active"
set activeF2 to cCon does not contain "media: autoselect (<unknown type>)"
set aRec to (current application's NSDictionary's dictionaryWithDictionary:{devName:aDevName, isActive:(activeF1 and activeF2), ifconfigRes:cCon})
(aResList's addObject:aRec)
set aCount to aCount + 1
end repeat
set activeIF to filterRecListByLabel(aResList, "isActive == [c]%@", {true}) of me
return activeIF as list
end getActiveNetworkInterfaceDeviceName
--http://qiita.com/szk-3/items/8bbe841eb0295caee6b0
on regexMatches(aText as text, pattern as text)
set regularExpression to current application's NSRegularExpression's regularExpressionWithPattern:pattern options:0 |error|:(missing value)
set aString to current application's NSString's stringWithString:aText
set matches to regularExpression's matchesInString:aString options:0 range:{location:0, |length|:aString's |length|()}
set matchResultList to {}
repeat with match in matches
set mRes to {}
repeat with i from 0 to (match's numberOfRanges as integer) - 1
set end of mRes to (aString's substringWithRange:(match's rangeAtIndex:i)) as text
end repeat
set end of matchResultList to mRes
end repeat
return matchResultList
end regexMatches
--リストを指定デリミタを入れつつテキスト化
on retDelimedText(aList, aDelim)
set aText to ""
set curDelim to AppleScript's text item delimiters
set AppleScript's text item delimiters to aDelim
set aText to aList as text
set AppleScript's text item delimiters to curDelim
return aText
end retDelimedText
--先頭から指定キャラクタまでを抽出して返す
on retStrFromTopToAstr(aStr, aTarg)
set aLen to length of aTarg
set anOffset to offset of aTarg in aStr
set bStr to text 1 thru (anOffset - aLen) of aStr
return bStr
end retStrFromTopToAstr
--リストに入れたレコードを、指定の属性ラベルの値で抽出(predicateとパラメータを分離)
on filterRecListByLabel(aRecList, aPredicate, aParam)
set aArray to current application's NSArray's arrayWithArray:aRecList
set aPredicate to current application's NSPredicate's predicateWithFormat:aPredicate argumentArray:aParam
set filteredArray to aArray's filteredArrayUsingPredicate:aPredicate
set bList to filteredArray as list
return bList
end filterRecListByLabel
code-block
AppleScript can renew DHCP. But it is not simple. I wrote such a script in 7 years ago and I just fixed now.
-- Created 2016-12-17 by Takaaki Naganoya
-- Updated 2023-03-06 by Takaaki Naganoya
-- 2016-2023 Piyomaru Software
use AppleScript version "2.4"
use scripting additions
use framework "Foundation"
set aDevRes to getActiveNetworkInterfaceDeviceName() of me
--set aDevList to devName of (first item of aDevRes)
repeat with i in aDevRes
set aDev to devName of contents of i
log aDev
--http://superuser.com/questions/86956/release-renew-ip-address-via-terminal-in-os-x
do shell script ("ipconfig set " & quoted form of aDev & " DHCP") with administrator privileges
end repeat
--ifconfigからactiveなデバイス名だけをピックアップする
on getActiveNetworkInterfaceDeviceName()
set aRes to (do shell script "ifconfig")
set aList to paragraphs of aRes
set devNameList to {}
repeat with i in aList
set j to contents of i
set bRes to regexMatches(j, "^[^\\t]*") of me
if bRes is not equal to {{""}} then
set the end of devNameList to contents of item 1 of item 1 of bRes
end if
end repeat
--Parse ifconfig results by device name list
set curDelim to AppleScript's text item delimiters
set AppleScript's text item delimiters to devNameList --かなりトリッキー
set tmpList to text items of aRes
set AppleScript's text item delimiters to curDelim
--initialize
set bList to rest of tmpList --remove blank item at top
set aCount to 1
set aResList to current application's NSMutableArray's alloc()'s init()
repeat with i in bList
set aCon to contents of i
set aDat to contents of item aCount of devNameList
--Device Name
set aDevName to retStrFromTopToAstr(aDat, ":") of me
set bCon to paragraphs 2 thru -1 of aCon
set cCon to aDat & retDelimedText(bCon, return) of me
--Activeなdeviceを抽出するための条件付け
set activeF1 to cCon contains "status: active"
set activeF2 to cCon does not contain "media: autoselect (<unknown type>)"
set aRec to (current application's NSDictionary's dictionaryWithDictionary:{devName:aDevName, isActive:(activeF1 and activeF2), ifconfigRes:cCon})
(aResList's addObject:aRec)
set aCount to aCount + 1
end repeat
set activeIF to filterRecListByLabel(aResList, "isActive == [c]%@", {true}) of me
return activeIF as list
end getActiveNetworkInterfaceDeviceName
--http://qiita.com/szk-3/items/8bbe841eb0295caee6b0
on regexMatches(aText as text, pattern as text)
set regularExpression to current application's NSRegularExpression's regularExpressionWithPattern:pattern options:0 |error|:(missing value)
set aString to current application's NSString's stringWithString:aText
set matches to regularExpression's matchesInString:aString options:0 range:{location:0, |length|:aString's |length|()}
set matchResultList to {}
repeat with match in matches
set mRes to {}
repeat with i from 0 to (match's numberOfRanges as integer) - 1
set end of mRes to (aString's substringWithRange:(match's rangeAtIndex:i)) as text
end repeat
set end of matchResultList to mRes
end repeat
return matchResultList
end regexMatches
--リストを指定デリミタを入れつつテキスト化
on retDelimedText(aList, aDelim)
set aText to ""
set curDelim to AppleScript's text item delimiters
set AppleScript's text item delimiters to aDelim
set aText to aList as text
set AppleScript's text item delimiters to curDelim
return aText
end retDelimedText
--先頭から指定キャラクタまでを抽出して返す
on retStrFromTopToAstr(aStr, aTarg)
set aLen to length of aTarg
set anOffset to offset of aTarg in aStr
set bStr to text 1 thru (anOffset - aLen) of aStr
return bStr
end retStrFromTopToAstr
--リストに入れたレコードを、指定の属性ラベルの値で抽出(predicateとパラメータを分離)
on filterRecListByLabel(aRecList, aPredicate, aParam)
set aArray to current application's NSArray's arrayWithArray:aRecList
set aPredicate to current application's NSPredicate's predicateWithFormat:aPredicate argumentArray:aParam
set filteredArray to aArray's filteredArrayUsingPredicate:aPredicate
set bList to filteredArray as list
return bList
end filterRecListByLabel
It is called "GUI Scripting" AppleScript.
AppleScript works by calling other application's function via internally.
GUI Scripting works by simulating users operation via externally.
https://piyomarusoft.booth.pm/items/4230018
This is whole GUI Scripting technic book written in Japanese.
But you can not press "a" and "w" keys in the same time by using GUI Scripting AppleScript.