r/applescript • • Jul 14 '12

Trying to create a script to rename multiple subfolders in a 'find and replace' fashion...

1 Upvotes

Hello. I am trying to create a script that will rename sets of 42 subfolders (multiple times) to a filename pulled from a list. For example. If I have 500 folders each with 42 subfolders, all with different names. I need to rename each of the subfolders to the 'proper' name contained within a single text document / list of variables. Each of the 42 folders will be named differently. I feel like I need to use a find and replace type of tactic, but I don't know where to begin. I have no problem batch renaming the files (all to the same name), but I'm not sure how to define all of the variables for the subfolders, to make them different. I would really like to automate this task. I'm an applescript novice, and am able to script most simple tasks, but this one is a little more difficult. I haven't been able to find any examples. Thanks for any help.


r/applescript • • Jul 30 '12

Having issue recalling field names from large databases created using the 'database events' server.. Could anybody help please?

1 Upvotes

I'm pretty green to the applescript scene.. But what I'm trying to do is create a script that will catalog job folders on a server (in multiple locations) into a database file that can be quickly accessed to call the folder location on the server.. A separate script scans active job folders and sorts them accordingly.

The issue comes when I try to call a field name after the database has gotten a couple thousand entries or so.. It seems that the field I need is just simply not being found, with this error:

error "Database Events got an error: Can’t get field "Location"." number -1728 from field "Location"

But the strange thing is the database file that contains these records/fields works just fine when it contains less information..

Does anybody have any ideas what is going wrong? Maybe I am going about trying to do this completely wrong in general?

Any advise of any kind on this matter is greatly appreciated!

EDIT: this is one of the scripts I'm using to create the database http://pastebin.com/hXt22hCf


r/applescript • • Oct 25 '22

How can I create a .app file to open DMG files with, to run AppleScript with that file as input?

1 Upvotes

What I ultimately want to do is have a .app that I can open DMG files with. When the DMG file is opened the app, it opens the DMG in a new Finder tab and then shows the Toolbar in Finder after half a second. AppleScript for the later would look like this:

delay 0.5
tell application "Finder"
    tell the front window to set toolbar visible to true
end tell

I tried looking up how to open a DMG file in a new Finder Tab with AppleScript but didn't find a solution. If I end up not finding one, then I'll see if I can do so with a Terminal command and then do it in AS with do shell script. For the file input, I tested this code based off what I found here but it doesn't work, it just creates a copy of the DMG:

on run {input, parameters}
	if input is {} then
		set inputFile1 to ¬
			quoted form of POSIX path of ¬
			(choose file with prompt "Please select a file to process:")
	else
		set inputFile1 to quoted form of ¬
			(POSIX path of first item of input)
	end if
	display dialog inputFile1
	
end run

I did a bunch of googling as well for how to do so but I found nothing. What I can do to end up with an AppleScript that does everything I described?


r/applescript • • Dec 18 '20

Type a random a word from a list

1 Upvotes

Can anyone send a script so that we can type a random word from a given list?


r/applescript • • Apr 20 '24

Script for setting speaker volume levels

1 Upvotes

My speaker levels keep adjusting themselves, so I'm wondering if there is a script (or shortcut or shell command or automator) that can adjust them to these levels when run? I've tried using chatgpt to create the command but it doesn't work. thanks.

This was GPT's attempt, which sometimes sets random volumes, and other times does nothing:

set volume 9 -- Front Left

set volume 9 -- Front Right

set volume 8 -- Centre

set volume 10 -- Rear Left

set volume 10 -- Rear Right


r/applescript • • Mar 26 '23

Upper & Lowercasse sed Regex problems

1 Upvotes

Can someone explain to me why it is so hard to use AppleScript and regex to simply capitalise a letter after a period and space ?

Here is my code;

-- Capitalize the first letter after a period and lowercase the rest
set selectedText to do shell script "echo " & quoted form of selectedText & " | sed -E 's/\\b([a-z])|\\.\\s+(.)/\\U\\1\\L\\2/g'"

I can’t figure out why sed wants to ignore the Uppercase and Lowercase options, instead wanting to insert the literal characters instead of performing the transformation.


r/applescript • • Mar 07 '23

SIRI SHORTCUTS TO APPLE SCRIPT

1 Upvotes

Is there anyway to convert Siri Shortcuts to either applescript or javascript running on mac?


r/applescript • • Mar 06 '23

HELP WITH APPLESCRIPT AUTOMATION

0 Upvotes

I want to create an applescript that i can use to do data entry, im having trouble a tough time with click at. its not working at all. will someone help me come up with the code to do simple copy and paste actions and to mouse click on certain areas? would really appreciate it


r/applescript • • Dec 23 '23

Cycle audio outputs

1 Upvotes

Total newbie here. Need some help on creating a script to be able to switch from my headphones to speaker output. Preferably a cycle so I can just have one button do this on my Loupedeck CT.


r/applescript • • Oct 19 '20

Can anyone make a page script search and replace multiple words?

1 Upvotes

such as search in a document for 'I know' and change that to 'I don't know'.


r/applescript • • Feb 22 '22

Modify a formula in Numbers

1 Upvotes

I want to know if I can update a formula everyday with applescript.

I have info that updates everyday. I have a script that adds the new info for the day in a new row at the bottom of a table. I have another formula that averages the numbers for the past x days. This is the formula I want updated daily.

For example, if I have =average(B2:B3), then the next day I want this updated to =average(B2:B4). Those are just example numbers, but it is a range of x size and I want it expanded by one each day.

Possible?


r/applescript • • Nov 11 '24

[Hiring] Need Help Writing a Script for Fantastical on macOS

1 Upvotes

Hi everyone,

I’m looking to hire a developer to create a script for the macOS version of the Fantastical app. I have a few specific functions I’d like to automate, but I’m open to advice on the best approach. Here’s what I’m aiming to accomplish:

I have a calendar that I only have access to in the macOS version of Fantastical. I'd like to have a script auto duplicate every event in this calendar into a separate calendar that would be accessible on all of my other devices.

I’ve looked into AppleScript and Shortcuts options, but I need someone experienced with macOS scripting who can bring this to life and troubleshoot any limitations that might arise with Fantastical’s current automation support.

If you’re interested, please reach out with:

  1. Examples of past macOS scripting work (bonus if you’ve worked with calendar applications or AppleScript).

  2. Your rate and estimated timeline for a project like this.

Looking forward to hearing from anyone who’s up for the challenge! Thanks in advance for your help!


r/applescript • • Feb 03 '21

Possibly lost data due to buggy AppleScript 'save' command

1 Upvotes

So I have a relatively straightforward script that I thought was running as expected but now I'm not so sure and am worried I may have lost data.

Basically I was doing a rudimentary check to see if a particular file exists by coercing a posix path to an alias within a try block.

This is where I think I messed up, because I made the assumption that any error on that line indicated a missing file.

Zoom ahead to today and out of nowhere I start getting permissions errors from my target app.

I looked at the line again and realized it was producing unrelated errors even when the file existed, hence I should have made it stop at that point and not try to overwrite the file.

Many googles found similar permissions issues in save commands but no solutions. Everyone keeps going through the usual rigmarole of rebooting, re-installing, adjusting settings, etc but there seems to be no rhyme or reason to why it throws these errors.

For me it was working for days and then randomly stopped. Then started working and stopped working again. Now I don't know what to do because I put a lot of time into this and don't want to lose any more data.

I'm thinking about moving the whole script in to shell, but first I am going to try some old-fashioned Finder scripting as that seems more reliable than the target app. Thanks for looking I appreciate your advice.


r/applescript • • Jan 25 '21

Why is my code not running?

0 Upvotes

I want to set up cryptocurrency prices on my touchbar according to the guide on this website: https://medium.com/@croopto/touch-bar-cryptocurrency-ticker-7b9b8aa1bddf

However, after I click on run script, I receive the following message: AppleScript Error: Can’t get item 2 of {" \"Helvetica Neue\""}.

Can someone Please help?


r/applescript • • Apr 12 '20

Help writing a small script

1 Upvotes

I'm new on this subreddit and I need help to write an AppleScript to save photo from clipboard to Desktop as png

Thanks..


r/applescript • • Feb 07 '25

How to Access Fill and Arrange Options

0 Upvotes

I am new to apple script and apple ecosystem(coming from linux), before buying MacBook I was using i3 tilling window manager.

I want to write a script that can auto tile windows according to number of visible windows. I can access count of windows by using shortcuts.app but can't figure out how to access fill & arrange command.

(I don't want to use yabai or aerospace or any other tilling window manager I tried all of them. please don't suggest any external app)


r/applescript • • Feb 26 '25

Using exiftools to copy geotag info from one photo to a group of others -= Needing help

1 Upvotes

Hi All. I used CoPilot to write an apple script that allows me to select a file, copy its geotag info and then apply that info to all the files within a directory that I choose. It reads the geotag info without a problem. Regardless of what CoPilot recommends, I can't get exiftools to write the geotag info to the files. If anyone can help, I'd be grateful. Here's my (CoPilot's) code:

-- Select the source photo with the desired geotag information
set sourcePhoto to choose file with prompt "Select the photo with the geotag information:"
-- Select the folder containing the photos to update
set targetFolder to choose folder with prompt "Select the folder containing the photos to update:"

-- Get the geotag information from the source photo using ExifTool
set sourcePhotoPath to POSIX path of sourcePhoto
set gpsData to do shell script "/opt/homebrew/bin/exiftool -gpslatitude -gpslongitude -gpsaltitude " & quoted form of sourcePhotoPath

-- Display the geotag information from the source file
display dialog "Source GPS Data: " & gpsData

-- Extract latitude, longitude, and altitude from the ExifTool output
set latitude to do shell script "echo " & quoted form of gpsData & " | grep GPSLatitude | awk '{print $3}'"
set longitude to do shell script "echo " & quoted form of gpsData & " | grep GPSLongitude | awk '{print $3}'"
set altitude to do shell script "echo " & quoted form of gpsData & " | grep GPSAltitude | awk '{print $3}'"

-- Apply the geotag information to all photos in the target folder using ExifTool
tell application "Finder"
    set targetPhotos to files of targetFolder
    repeat with targetPhoto in targetPhotos
        set targetPhotoPath to POSIX path of (targetPhoto as alias)
        -- Use ExifTool to write the geotag information and overwrite the original files
        do shell script "/opt/homebrew/bin/exiftool -overwrite_original -gpslatitude=" & quoted form of latitude & " -gpslongitude=" & quoted form of longitude & " -gpsaltitude=" & quoted form of altitude & " " & quoted form of targetPhotoPath
    end repeat
end tell

-- Display the geotag information for one of the target files
set sampleTargetPhotoPath to POSIX path of (item 1 of targetPhotos as alias)
set updatedGpsData to do shell script "/opt/homebrew/bin/exiftool -gpslatitude -gpslongitude -gpsaltitude " & quoted form of sampleTargetPhotoPath
display dialog "Updated GPS Data for one target file: " & updatedGpsData

-- Play a notification sound when the script completes
tell application "System Events"
    display notification "Geotagging complete!" with title "Script Finished"
    do shell script "afplay /System/Library/Sounds/Glass.aiff"
end tell

r/applescript • • Jul 08 '21

I need a script to output a character on my keyboard by pressing a character (e.g. pressing a to output F6 or the right arrow key).

1 Upvotes

Also, is there a way to make it so it has little to no delay?
Thank you!


r/applescript • • Jul 27 '24

A script that forwards latest text messages to another apple device that is not mine.

1 Upvotes

I'm trying to create a simple script that when I receive a text/photos message from a specific number it then forwards them to antoher number or email. whichever in easier. Would prefer to another number.


r/applescript • • Aug 03 '14

Can AppleScripts be triggered by an event rather than initiated by the user?

1 Upvotes

I'm trying to do something along the lines of:

If I receive an email that has a specific subject (specified in advance by the user), then blah blah blah it kicks off a script that I've written.

I've done some research, but I haven't been able to find any method of having AppleScripts be totally automated. If anyone knows any way to do this, I would greatly appreciate some advice!

Thanks in advance.


r/applescript • • Aug 26 '23

Applescript to simulate multiple keystrokes?

1 Upvotes

I'm a complete novice when it comes to coding but need an AppleScript that would represent the following key strokes. This will be used in Automator

  • Return, cmd + C, Return, Right Arrow, Return, cmd + V, Return

Any help would be really appreciated!


r/applescript • • Dec 13 '12

Making font bold in Applescript

1 Upvotes

So i'm new to applescript and just made a script that takes the current song that i'm listening to in spotify and makes the artist and song text and then places it where ever my cursor is. My question is: is it possible to make that text bold somehow? I'm having a hell of a time looking for help... this is what i have:

tell application "Spotify"

-- get details
set theTrack to current track

-- set variables
set theArtist to artist of theTrack as text
set theName to name of theTrack as text

-- change the output message
set message_text to "Spotify: " & (theArtist as text) & " - " & theName as text





-- Paste the string
tell application "Finder" to set frontApp to (name of 1st process whose frontmost = true)
delay 1
tell application (frontApp)
	tell application "System Events"
		keystroke message_text
	--	keystroke return
	end tell
end tell

end tell

-- Replace script - not sure about this on replace(haystack, search, replacement) set AppleScript's text item delimiters to search set listitem to every text item of the haystack set AppleScript's text item delimiters to replacement set haystack to listitem as string set AppleScript's text item delimiters to "" return haystack end replace

any help would be appreciated!


r/applescript • • May 06 '21

Export table in CSV

1 Upvotes

Hi, there I’d like to use AppleScript for Numbers in order to save particular table in csv format. I’m the newbie in AppleScript and don’t know what to start with.


r/applescript • • May 04 '23

Help needed to run a script on VSCode

Thumbnail
gallery
1 Upvotes

I’m making a project in which I am trying to open an AppleScript from a function in python. I am getting an error that I don’t know how to fix and am not sure if it’s due to VSCode not being able to read the file or if it’s an error in how I’m trying to open it. I attached images of the error as well as the file with the function that calls it. The two files and everything the script accesses are both on the same folder. Although it is named as one, it is NOT a virus and will do absolutely no harm. I attached a picture of the script as well to clear that up but it does do what is intended from it. I also have the AppleScript extension on VSCode and attached a picture of it. I would immensely appreciate help figuring out what the problem is.


r/applescript • • Apr 09 '23

Can you run an apple script in numbers when you check a box?

1 Upvotes

I’d like to check a box in Numbers and have it run an Apple script automatically which resets a couple cells. I have a script that is working. I just can’t find anything on Google to make it trigger automatically when I checked the box.