PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0
Showing posts with label applescript. Show all posts
Showing posts with label applescript. Show all posts

Sunday, November 6, 2022

[FIXED] How do I add a Name Prefix to a Contact using AppleScript?

 November 06, 2022     applescript, contacts, macos     No comments   

Issue

Apple's Contacts App had a defined field for a name prefix (e.g. "Dr.").

Using AppleScript if I retrieve the name property, the prefix is included. However, there does not appear to be/exist a prefix property. There IS a suffix property which I am able to read and write, but I need to be able to specifically WRITE (e.g. add) a prefix to a contact.

Any/All help would be appreciated!!


Solution

In the AppleScript dictionary (⇧⌘L ) for Contacts, look at the properties of the class Person.

If you have added a Prefix to the contact via, e.g., Contacts > Card > Add Field, then it is assigned to the title property.

Example AppleScript code:

tell application "Contacts"
    set theContact to the first person ¬
        whose title is not missing value
    return title of theContact
end tell


Answered By - user3439894
Answer Checked By - Marie Seifert (PHPFixing Admin)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

Wednesday, November 2, 2022

[FIXED] How to create new file in Finder and open it?

 November 02, 2022     applescript, file     No comments   

Issue

For some reason Finder on Mac doesn't come with create new file functionality. The fastest way I've found to create a new file is to drag the finder path into Terminal and create a file there... which is super annoying

I wrote an apple script to automatically create a new file and bound it to a shortcut. It works perfectly, except that I can't figure out how to open the new file from within the applescript. I'm pretty sure the error stems from POSIX / UNIX paths but couldn't find a way to get this to work even when I put POSIX next to file, currentDir etc.

Here's my script:

set file_name to display dialog "File Name" default answer "untitled" with icon note buttons {"Cancel", "Continue"} default button "Continue"
set file_name to (text returned of file_name)

tell application "Finder"
    set theWin to window 1
    set currentDir to POSIX path of (target of theWin as alias)
    
    make new file at (the target of the front window) as alias with properties {name:file_name}
    set currentPath to (currentDir & file_name) as string
    open file currentPath
end tell

The script creates the file, then errors out saying it can't find the file to open it.


Solution

I cleaned up the code a bit and got rid of unnecessary lines.

set fileName to text returned of (display dialog "File Name" default answer ¬
    "untitled" with icon note buttons {"Cancel", "Continue"} default button 2)

tell application "Finder" to set newFile to (make new file at Finder window 1 ¬
    with properties {name:fileName}) as alias

delay 0.1
do shell script "open -e " & quoted form of POSIX path of newFile

Note: If you're trying to use open -a instead of open -e... And you were getting error messages, try using open -b. This option allows you to open the files with the application by using the application's bundle identifier to identify the application to use.

For example, if I want to open the files with Visual Studio Code.app by using it's bundle identifier... The do shell script command would look like this...

do shell script "open -b com.microsoft.VSCode " & quoted form of POSIX path of newFile

If you do not know how to get the bundle identifier for the application to use when opening the file, this following AppleScript code allows you to choose an application then copies it's bundle identifier to the clipboard. Then just go back and paste that into the do shell script "open -b " command.

activate
set chosenApp to name of (choose application with title ¬
    "Choose App" with prompt "Choose App")
delay 0.1

tell application chosenApp to set appID to id

set the clipboard to appID

Be sure to grant Terminal.app the appropriate permissions in System Prefs.



Answered By - wch1zpink
Answer Checked By - Senaida (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

Tuesday, July 12, 2022

[FIXED] How to use Applescript to delete Conversations whose senders contain email addresses from the Messages app

 July 12, 2022     applescript, messages     No comments   

Issue

I want to use applescript to delete conversations from people who sent me messages using email addresses. I want to keep all conversations from mobile numbers, but delete all conversations, in which my correspondent is an email address.

I've tried:

tell application "Messages"
    tell every item
        delete (every item whose sender contains ".com")
    end tell
    save
end tell

Solution

All scriptable applications have an AppleScript Dictionary that can be accessed from Script Editor via the Window --> Library menu. Reading through an application's dictionary can help you obtain the proper terms for generating a script to do your bidding.

The script below will successfully create a list of chat IDs of all chats (conversations) wherein at least one participant is using an email address. I have not tested the delete section, since I am not interested in deleting anything. I strongly recommend that you run Time Machine or another backup service BEFORE executing that portion of the script, just in case you get unexpected results.

set chatsToKill to {}
tell application "Messages"
    set allChats to every chat
    repeat with eachChat in allChats
        set thePeeps to participants of eachChat
        repeat with oneParticipant in thePeeps
            if oneParticipant's handle contains "@" then
                if chatsToKill does not contain eachChat's id then set end of chatsToKill to eachChat's id
            end if
        end repeat
    end repeat
    repeat with deathChat in chatsToKill
        delete item 1 of (get every chat whose id = deathChat)
    end repeat
end tell


Answered By - Craig Smith
Answer Checked By - Marilyn (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

[FIXED] How to get message count of mac messages app in applescript *Not Mail*

 July 12, 2022     applescript, messages, scripting     No comments   

Issue

I am trying to make a script that returns the amount of unread messages in messages app on a mac, I know the code for mail but can't figure this problem out.


Solution

Check some of the Apple Scripts On this thread

Specifically, this one looked promising although it didn't work for me:

tell application "Messages" to "clear unread messages"

You should be able to:

  1. Open Script Editor
  2. Copy the above script into it
  3. Click the Run icon to run the script


Answered By - Timothy Tripp
Answer Checked By - Willingham (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

[FIXED] How to send an imessage text with applescript, only in provided service?

 July 12, 2022     applescript, imessage, messages, send     No comments   

Issue

Can somebody show me how to send a message directly to the user of iMessage via Messages app?

tell application "Messages"
    if service type of service of buddy whose name is ("Name here" is "iMessage") then set x to 1
    if service type of service of buddy whose name is ("Name here" is "iMessage") then set x to 2
    if service type of service of buddy whose name is ("Name here" is "iMessage") then set x to 3

    send "Message" to buddy "mail of name" of service x
end tell

I need to send a message to an account only via iMessage, not via google talk, AIM, bonjour. Thank you!


Solution

Instead of having to hard-code the iMessage service, you can find it automatically:

  1. Save the following script as sendMessage.applescript (Note: make sure to choose the Text option).
  2. Execute it by running: osascript sendMessage.applescript 1235551234 "Hello there!".
  3. This will send an iMessage to the phone number 123-555-1234 containing the text "Hello there!".

sendMessage.applescript:

on run {targetBuddyPhone, targetMessage}
    tell application "Messages"
        set targetService to 1st service whose service type = iMessage
        set targetBuddy to buddy targetBuddyPhone of targetService
        send targetMessage to targetBuddy
    end tell
end run


Answered By - Senseful
Answer Checked By - Marie Seifert (PHPFixing Admin)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg

Monday, July 11, 2022

[FIXED] How do I CLICK the 'delete' button in the popup from MESSAGES in MacOS Big Sur using AppleScript?

 July 11, 2022     applescript, click, macos-big-sur, message, popup     No comments   

Issue

What is the simple way to get the 'delete' button 'clicked' in response to the popup pictured below from the Messages app? I've tried more variations than I care to admit and am feeling humbled.

This code works fine if I want to 'click' the 'cancel' button in the popup.

But nothing I have tried has worked to click the 'delete' button.

Messages popup after delete message pulldown

tell application "Messages"
    activate
end tell

tell application "System Events"
    key code 2 using command down
end tell


tell application "System Events"
    set frontmost to true
    delay 1
    click button "Cancel"
end tell

Solution

This should work for you.

tell application "System Events" to tell application process "Messages"
    set frontmost to true
    repeat until frontmost
        delay 0.1
    end repeat
    click UI element "Delete" of sheet 1 of window 1
end tell


Answered By - wch1zpink
Answer Checked By - David Marino (PHPFixing Volunteer)
Read More
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Older Posts Home

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
All Comments
Atom
All Comments

Copyright © PHPFixing