AppleScript change Terminal ProcessArgumentsInTitle boolean - terminal

I want to change a specific terminal setting called ShowActiveProcessArgumentsInTitle to false.
tell application "Terminal"
set ProfilesNames to name of every settings set
repeat with ProfileName in ProfilesNames
set title displays file name of settings set ProfileName to false
end repeat
end tell
output
Terminal got an error: Can’t set title displays file name of settings set "Grass" to false.

simply goto terminal setting area and change profile

Related

reload Terminal preferences .plist after change

I used plutil to edit the plist. then I placed in under /User/<myUsername>/Library/Preferences/com.apple.Terminal.plist. I want it to update the settings without reboot the application. How do I do this? using defaults read com.apple.Terminal doesn't seem to make the changes take effect. I added a terminal profile to the plist and want the changes to take effect.
I tried making an import profile with AppleScript but long story short it's not 100% possible. if you store window 1 so it's the same var in-between delays right after open it errors more times.
on run argv
set importScript to first item of argv
set flag to application "Terminal" is not running
tell application "Terminal"
open importScript
delay 1.0E-5
activate
if flag then close back window
do script "exit" in window 1
delay 0.5
close window 1
end tell
end run
there is no need for editing plists just a simple AppleScript. the limitations of this are you must have _oti_<yourProfileId> in your terminal profile default header and change the title when running your terminal profile to prevent accidental closures when installing the same profile of an already running app
import.applescript
on run argv
set importScript to first item of argv
set closeScript to second item of argv
set profileId to third item of argv
do shell script "open -a Terminal " & importScript
do shell script "osascript " & closeScript & " _oti_" & profileId
end run
closeMe.applescript
on run argv
set c to first item in argv
tell application "Terminal"
set wList to every window
repeat with app_window in wList
set wname to name of app_window
if wname contains c then
do script "exit" in app_window
delay 0.312
close app_window
end if
end repeat
end tell
end run
and then you can call the profile using this AppleScript
on run argv
set flag to application "Terminal" is not running
set scpt to first item in argv
set n to second item in argv
set p to third item in argv
tell application "Terminal"
set newTab to do script scpt
set badFlag to back window is equal to window 1
if p is not equal to "" then set current settings of newTab to settings set p
set custom title of newTab to n
activate
if flag and (not badFlag) then
do script "exit" in back window
delay 0.1
close back window
end if
end tell
end run

Applescript does not run user command

I need the applescript to run tabset test command to change the name of the current tab of iTerm.
-- Launch iTerm and log into multiple servers using SSH
tell application "iTerm"
activate
create window with default profile
set newWindow to (create window with default profile)
set Servers to paragraphs of (do shell script "/bin/cat $HOME/serverlist")
repeat with nextLine in Servers
if length of nextLine is greater than 0 then
tell current window
create tab with default profile
tell current session of newWindow
do shell script "export PATH='/usr/local/bin:$PATH'; tabset test "
end tell
end tell
end if
end repeat
tell first tab of current window
close
end tell
tell second window
close
end tell
end tell
The problem is tabset test does not work, and there is no any error prompted.
The tabset command could be installed via npm install -g iterm2-tab-set
Ted Wrigley is right. I should use iTerm's write command to type the text into the window.

Setting Finder label via AppleScript on High Sierra

I'm trying to use AppleScript to set the label of a file to a specific colour; or rather, I already have a script that used to work, but ever since upgrading to High Sierra it no longer does.
I've stripped it down to the absolute basics (always sets label to green):
on run theArguments
set theFile to POSIX file (item 1 of theArguments)
tell application "Finder" to set (theFile's label index) to 6
end run
If you save this to a file (green.scpt) then you can run it from Terminal with the following command:
osascript ~/Downloads/green.scpt ~/Downloads/green.scpt
(substitute the paths for wherever you store the script)
This should turn the script's label in the Finder to green, but doesn't (at least on High Sierra), instead giving the following error message:
/Users/haravikk/Downloads/green.scpt: execution error: Finder got an error: Can’t set label index of file "Users:haravikk:Downloads:green.scpt" to 6. (-10006)
Am I doing something wrong here? If not, and this is a bug, then is there some other way to change a file's label via script?
You can try to use tell application before change label index
on run theArguments
tell application "Finder"
set thisItem to POSIX file theArguments as alias
if label index of thisItem is not 6 then
set the label index of thisItem to 6
end if
end tell
end run
This works for me (added "as alias"):
on run theArguments
set theFile to POSIX file (item 1 of theArguments) as alias
tell application "Finder" to set (theFile's label index) to 6
end run
Note though that labels are long gone, and have been replaced with tags.

Get iTerm location Applescript

I would like to know how to get the current location of the current session in iTerm using Applescript.
I have tried all sorts of things. The dictionary is very difficult for me to understand.
Here is my latest attempt
tell application "iTerm"
tell the current session of current terminal
set theSelection to attachment file name
display dialog theSelection
end tell
end tell
And the error this produces is:
error "iTerm got an error: Can’t get file name of current session of current terminal." number -1728 from file name of current session of current terminal
I just want the location the iTerm session is currently in: /Users/SuperCoolGuy/Desktop
This is ugly...
tell application "iTerm"
if not (exists terminal 1) then reopen
set mySession to current terminal's current session
tell mySession
write text "pwd"
set sessionContents to it's text
end tell
end tell
set myPath to paragraph -2 of (do shell script "grep . <<< " & quoted form of sessionContents)
If somebody stumbles upon this question, there's another option now with Shell integration. With it you can access the path in AppleScript using the iTerm defined variable session.path:
activate application "iTerm"
tell application "iTerm"
tell current session of current window
set myTerm to (variable named "session.path")
write text "echo this is the current path: " & myTerm
end tell
end tell
That information isn't currently available through iTerm's AppleScript interface. The only exposed properties of the session object having to do with what's running in it (as opposed to its visual appearance) are contents and tty, and those aren't what you're looking for here.

TextExpander and AppleScript to get file path on Mac

I would like to create a TextExpander snippet that will prompt me to choose a file in the Finder and copy the file path to the text editor I am working in.
It should work like this:
I am working in NVAlt
I enter the TextExpander command (e.g. ;path)
I am prompt top choose a file
The file path is copied to the note I am working in.
I figured I'll do it using AppleScript, so I tried this:
set source_folder to choose file with prompt "Please select a file."
tell application "System Events"
set item_list to POSIX path of every disk item of source_folder
end tell
return "path:" & item_list
But it is not returning anything to the text note I am working in...
Any suggestion how I should do it?
PS: I used the POSIX command to the folder name as ".../.../.../" instead of "...:...:..."
There are multiple things wrong in the script but instead of trying to correct your script I've looked what textExpander tells me to do. On the help section about textExpander on smilesoftware.com site they say:
The script executes in the context of the TextExpander application.
The script can perform various actions, but the snippet will expand to
whatever text is returned.
When looking at the your goal you simply need to coerce the returned alias from the choose file command into a string and return that. So a single line like below should be enough to use to return an HFS path to a file
return choose file with prompt "Please select a file." as string
if you want to return the file path as POSIX Path you only need this:
return POSIX path of (choose file with prompt "Please select a file.")
If you want the path to be prefixed with "path:" like in your example code:
return "path:" & (choose file with prompt "Please select a file.")
NOTE: there is an implicit coerce of the choose file results, no explicit coercion is needed.
EDIT: I've downloaded textExpander myself and it seems that showing dialog in the context of textExpander will behave wrong. So what I did was looking up the front most application and showing the dialog there, it's also better looking. Then I tell that application explicitly to show the choose file prompt and return the result of the choose file prompt. Here is the code:
tell application "System Events"
set applicationName to (name of every process whose frontmost is true) as string
end tell
using terms from application "AppleScript Editor"
tell application applicationName
set expansionString to (choose file "Please select a file.") as string
end tell
end using terms from
return expansionString

Resources