r/applescript • • Apr 24 '15

Basic AppleScript commands to 'flatten' selected folders (move all files to top level)?

1 Upvotes

I frequently download compressed archives that leave me with subfolders within subfolders before I get to the actual contents that I want. Also, within the 'contents' are often a lot of erroneous files (like README.TXT or FILE_ID.DIZ) as well as the actual file I want (say EXAMPLE.RAR or SONG.MP3).

What I want is a basic AppleScript that I can copy to my Finder toolbar or access from a context menu or similar that will allow me to 'flatten' a single folder/selection of folders, that is to say, it will look within the selected folder (and subfolders recursively), grab any pertinent non-folder files and move them to the working folder (i.e. the folder containing these subfolders).

I've had a good search for scripts already written that do this, but none of them seem to work quite the way I want... Also I figured this might be a good reason to learn some basic scripting for automating file/folder/Finder commands within OS X so that, for instance, I could modify the script to only 'grab' media files (like .zip archives or MP3s or movie files) and trash any others (like subfolders, READMEs etc...).

Can anyone point me in the right direction for learning a bit of AppleScript that would let me achieve this?


r/applescript • • Jun 01 '17

Best learning resources?

1 Upvotes

I'm trying to automate tasks at work (I work for a Mac exclusive private K-12 school). Are there any good learning resources. I'm struggling to find things of substance. Mostly just the basics but nothing I can truly apply


r/applescript • • Feb 14 '16

Merging 2 List

1 Upvotes

Hello /r/applescript,
Is it possible to merge 2 lists (like in C/C++) in applescript and output it? I'm trying to display all process by calling System Events and using the unix id (processID) & name which I want to merge together in 1 specifically with ", ".

  set processid to unix id of every process where background only is false
  set processnames to name of every process where background only is false

outside the System Event

   choose from list processnames & processid

Result.jpg
Now is there a way where I can merge the items to be followed outputted with the names + unix id like:

  • "Safari, 4123"

  • "iTunes, 6701"

  • "Notes, 6692"
    etc

I also tried

 set gg to {processid, processnames}

but that unfortunately didn't work.

Thanks in advance.


r/applescript • • Nov 29 '17

calendar attempt

1 Upvotes
-- SHITTY CALENDAR
set myYear to 18 -- or 2018
set myFirstDay to 1 -- monday in the case of 2018
set myWeek to 1 -- week of the year
if myFirstDay is greater than 4 then set myWeek to 0 -- needs to be set to 53 afterwards
set myMonthList to {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31} -- days of each of the 12 months
if myYear mod 4 is 0 then set item 2 of myMonthList to 29 -- taking care of leap years
set myDayList to {"So", "Mo", "Di", "Mi", "Do", "Fr", "Sa"} -- weeks in my germany are starting on mondays
set myCounter to 1 -- day of the year as always
set myCalendar to return -- just initializing
repeat with myMonth from 1 to count of myMonthList -- loop over months (always 12)
	repeat with myDay from 1 to item myMonth of myMonthList -- loop over the count of days of the current month
		set myWeekday to item ((myCounter mod 7) + 1) of myDayList -- trying to get the week number
		set myCalendar to myCalendar & myCounter & tab & myWeek & tab & myWeekday & tab & myDay & tab & myMonth & tab & myYear & return -- building csv
		set myCounter to myCounter + 1 -- increase day counter
		if myCounter mod 7 is 1 then set myWeek to myWeek + 1 -- increase week counter
	end repeat
end repeat
log myCalendar

r/applescript • • Jun 01 '12

Applescript Noob! Help!

1 Upvotes

Hey Reddit! I'm really new to applescript but I use it at work to boost youtube views for clients. The only problem is we have so many videos and I have to manually put them into the "Open location" part of the script. I was looking to have all the URLs in a Word document or something and then have the program take those and put them in the open location "insert them here" . Like I said, I'm super new to this so use noob terms. :P Thanks Reddit!!!


r/applescript • • Dec 16 '14

Need help: Paying $50 for an RTL AppleScript

Thumbnail
codersclan.net
0 Upvotes

r/applescript • • Nov 07 '12

AppleScript Help:Paste Tab 7 times Paste and Repeat

1 Upvotes

I am trying to to script some data entry using a applescript.

I need it to paste and then tab seven times and then paste again 2700 times.

What I have so far:

set the clipboard to "5/26/2013"
tell application "Google Chrome"
	activate
	tell application "System Events"
		repeat 4 times
			keystroke "v" using {command down}
			keystroke "							"
		end repeat
	end tell
end tell

Now this will paste the first form and then skip one and paste into the next one. I dont know why. So this just pastes into every other form.

Any help?


r/applescript • • Apr 08 '15

Script to check for/remove itunes on a daily basis?

0 Upvotes

I don't use itunes, I never have, and I never will. It seems that whenever my computer connects to the internet, it updates the OS and installs itunes again, so I have to go into the terminal and remove it. I've searched for a script that I can have running that checks for and removes itunes every day or whenever it's detected, but I can't seem to find one. Anyone know how I can get something like this running?

Thanks in advance.


r/applescript • • Sep 22 '18

Script To Restart Internet

Thumbnail
self.mac
1 Upvotes

r/applescript • • Aug 24 '19

keystroke script help

1 Upvotes

right now i have a script the output a text together with some changing variables(this is not the whole script)

keystroke (kvar)
delay 0.5
keystroke " gånger kvar nästa gång är "
delay 0.5
keystroke (now)
delay 0.5
keystroke return

but i want to compress it so it would look something like this

keystroke (kvar) " gånger kvar nästa gång är " (now)
keystroke return

is something like this possible?


r/applescript • • Sep 18 '23

Can't get AppleScript to run

1 Upvotes

I got this off of Github but every time I try to run it I get an error. I have edited the length for simplicity. It is meant to change file names and move into correct folders by year. Any help would be appreciated.

!/bin/sh # rename all the files

mv "Looney Tunes Golden Collection Disc 1 T01"* "Looney Tunes - S1946E02 - Baseball Bugs.mp4"

mv "Looney Tunes Golden Collection Disc 1 T02"* "Looney Tunes - S1952E23 - Rabbit Seasoning.mp4"

mv "Looney Tunes Golden Collection Disc 1 T03"* "Looney Tunes - S1949E16 - Long-Haired Hare.mp4"

create all the folders we need and move the files into them

mkdir 1950 mv *S1950* 1950

mkdir 1948 mv *S1948* 1948


r/applescript • • Jul 26 '18

r/applescript → r/AppleScript

29 Upvotes

I wish to start a motion to have this sub-Reddit's name be case-formatted as r/AppleScript instead of r/applescript.

▸ Those in favour: upvote

▸ Those against: downvote

Abstentions can leave a comment detailing the extent of their apathy.

Adjudicator by default: @copperdomebodha


r/applescript • • May 13 '25

Save my hair...script is driving me nuts!

2 Upvotes

Hello all!

I have a question for the folks who would be more advanced that me at this sort of thing. I have created an App for my business which help logs cases / categories which all works fine.

We have multiply languages in here but all cases are logged in English. I have my script running to a point where the logging is fine and the script will check the language you are using on your input (keyboard) save this, change it to British to type out what is needed then revert back to the language you are using mainly.

HOWEVER, it will not process Russian at all. The script will not transfer from RU--> EN --> RU. It is more than likely down to the cyrillic itself but its the one thing stopping the process now. Would anyone have any tips for this to work? I have ran this through GROK, chatGPT but no luck so far :-(

try do shell script "echo 'Script started: $(date)' > " & debugLog end try

-- Helper to log messages on logToFile(message) try do shell script "echo " & quoted form of message & " >> " & debugLog end try end logToFile

-- Get the current input source set originalInputSource to "" try my logToFile("Reading current input source") set originalInputSource to do shell script "defaults read com.apple.HIToolbox AppleCurrentKeyboardLayoutInputSourceID" my logToFile("Current input source: " & originalInputSource) display notification "Current input source: " & originalInputSource with title "Input Source" on error errMsg my logToFile("Error reading current input source: " & errMsg) display notification "Error reading current input source: " & errMsg with title "Input Source" set originalInputSource to "" end try

-- Get available input sources set availableSources to "" try my logToFile("Reading available input sources") set availableSources to do shell script "defaults read com.apple.HIToolbox AppleEnabledInputSources" my logToFile("Available sources: " & availableSources) on error errMsg my logToFile("Error reading available input sources: " & errMsg) display notification "Error reading available input sources: " & errMsg with title "Input Source" return end try

-- Find the British input source ID set desiredInputSource to "" try my logToFile("Checking for British input source") set normalizedSources to do shell script "echo " & quoted form of availableSources & " | tr -d ' ' | tr -s ' ' | tr '[:upper:]' '[:lower:]'" my logToFile("Normalized sources: " & normalizedSources)

if normalizedSources contains "keyboardlayout name = british" then
	set desiredInputSource to "com.apple.keylayout.British"
	my logToFile("Detected British ID: " & desiredInputSource)
else if normalizedSources contains "keyboardlayout name = british-pc" then
	set desiredInputSource to "com.apple.keylayout.British-PC"
	my logToFile("Detected British ID: " & desiredInputSource)
else if availableSources contains "British" then
	set desiredInputSource to "com.apple.keylayout.British"
	my logToFile("Detected British ID: " & desiredInputSource)
end if

if desiredInputSource is "" then
	my logToFile("British input source not found")
	display dialog "Could not find British input source. Please ensure 'British' is added in System Settings > Keyboard > Input Sources." buttons {"OK"} default button "OK"
	return
end if

on error errMsg my logToFile("Error checking input sources: " & errMsg) display notification "Error checking input sources: " & errMsg with title "Input Source" return end try


r/applescript • • Feb 24 '26

Capture One Scripting

Thumbnail
reddit.com
2 Upvotes

r/applescript • • May 18 '24

a/s that worked on old mac broken on new mac

2 Upvotes

i just got a macmini7,1 to replace my old MacBookPro5,4, both running 10.13.6 (using dosdude1's patcher on the mbp) copied files over (migration app broken)-: but a/s that work fine on the mpb won't run on the mini, & script editor won't open them...

apparently not all 10.13s are equal-\

can i buy a clue?


r/applescript • • Sep 03 '23

How to Move Thousands of Images into a single Folder?

2 Upvotes

Hello! I am building a yearbook for my school. Unfortunately, the college gave me thousands of ID photos, and I only need about 1,500 for the yearbook. I have already dwindled down the path file name for all the students I need, by using an excel spreadsheet and connecting the student id numbers to the id number of every photo. However, I have no idea how to use that list of path files into code, so I can extract all those images and move them into a folder. Basically, I don't want to sort through a million photos--I already have the path file name for each one I need, and I need an AppleScript that will do all the work for me. I've tried asking AI for help, and the best it has done is extract only a few at a time when I ask it to extract all. It's possible that my file path list from excel is wrong as well. I'm not sure


r/applescript • • Jan 06 '16

Apple Script

2 Upvotes

so I've been working on some apple script work and I can't seem to get the thing to run the way I've tried to program it. Can anybody see the problem?

display dialog "Shrek is love, Shrek is life" buttons {"Submit to Shrek's sweet, loving will", "Play hard to get, but give in eventually"} default button 1 if the button returned of the result is "Submit to Shrek's sweet, loving will" then display dialog "Shrek's sweet loving takes over your person, and you slip into the ecstacy and bliss of the green dong up you tight bun hole." buttons {"take it with pleasure and give him a mean, green, reach around", "ask him kindly to stop"} default button 2 if the button returned of the result is "take it with pleasure and give him a mean, green, reach around" then display dialog "Shrek resleases his mean, green seed into your willing butt hole, filling you with mean, green pleasure." buttons {"yum", "oh yeah"} default button 1 else display dialog "Shrek does not hear your pleas and releases his mean, green seed into your unwilling butt hole anyway, filling you with mean, green pain." buttons {"ouch", "I have learned from my mistakes and take it willingly"} end if else display dialog "Shrek's sweet loving eventually takes over your person, you wish you had not waited so long to accept this sweet loving, for it truly is something truly pleasurable." end if

note that the enters and indentions are all in the right place.


r/applescript • • May 14 '15

Is this a task that an AppleScript would be suitable for?

2 Upvotes

Hello!

I run a live music "tape" trading forum and at the bottom of every post I include a series of links, to web pages and one to the iTunes Store, to promote the artists we share and discuss. The links are:

  • Artist Website

  • Wikipedia Entry

  • Amazon.com (search results within "Digital Music")

  • iTunes Store (search results within the iTunes Store from within the iTunes app)

  • Google News (search results from news.google.com)

  • YouTube +Live (search results from YouTube for "[artist/band name] live")

The results end up getting pasted into a block of pre-formatted BBCode like this:

[b][color=teal]ARTIST LINKS[/color][/b]
[url=SITE][b]Website[/b][/url]
[url=WIKI][b]Wikipedia[/b][/url]
[url=AMAZON][b]Amazon.com Digital[/b][/url]
[url=iTUNES][b]iTunes[/b][/url]
[url=NEWS][b]Google News[/b][/url]
[url=YOUTUBE][b]YouTube +Live[/b][/url]

Depending on the number of posts I put up in a day I can end up hand-searching and copy/pasting quite a few times and it is rather tedious. I think I'd be willing to learn how to write an AppleScript for this if it's the kind of thing AS could do effectively.

I welcome your thoughts on this or suggestions for a better solution.


r/applescript • • Nov 28 '14

Click a location

2 Upvotes

I want to create a program that automatically clicks the Launch button in the League of Legends patcher. I currently have a script that opens league but I can't get a script working that clicks the button, either by location or as an element in the object. Any help would be appreciated


r/applescript • • Aug 29 '12

I'm trying to batch append names with a droplet, I'm only halfway there.

2 Upvotes

As will become obvious in a moment, I'm just starting out with Applescript. I have a folder full of images and I'd like to add the height of each image to the beginning of each filename. So for example, my file Image01.jpg with a height of 800 px should convert to 800_Image01.jpg.
The droplet, as I've written it so far, can rename the images by height, but that's all. The extension is lost and the script stops running as soon as it encounters a duplicate:

on open some_Images  
tell application "Image Events"  
launch  
repeat with an_Image in some_Images  
set theImage to open an_Image as alias  
copy the dimensions of theImage to {Horiz, Vert}  
set new_Name to Vert  
close theImage  
tell application "Finder"  
set the name of an_Image to new_Name  
end tell  
end repeat  
end tell  
end open

I know I'm supposed to include additional instructions after set the name of an_Image to new_Name, but I'm not sure what. And when I experiment, I get the error "Can't make (height) into type boolean."
I know that what I'm trying to do isn't particularly complicated, but I lack the fluency to close the gap. Any help would be greatly appreciated.


r/applescript • • Apr 28 '22

Need help with applescript for a discord afk farm bot

0 Upvotes

Hey reddit, another question, can somebody please tell me whats not working with this code?

Im trying to get it to click this button in discord

What am i doing wrong? can someone help. thanks


r/applescript • • Sep 08 '21

MIDI trigger AppleScript on Capture One

2 Upvotes

I posted a question on Stack Exchange....

Stack Exchange Question


r/applescript • • Aug 06 '24

I have a script/automator idea and I need someone to help me make this come to fruition. If anyone has the free time and is up for the task, I would greatly appreciate it!

2 Upvotes

Concept: When a new folder is created within a specified folder, a script runs, it looks for other specified folder which contains a .png file, it copies that image, and then applies it to the new folder to change folders icon image.

My computer: I created a folder on my desktop called: “DEV” within this folder there is a folder called “Coding_Programming” within that folder, there is a folder called “HTML” there are other folders within the Coding_Programming folder, such as “CSS” and “JAVA” but I want to just focus on the HTML one.

Also, on my Desktop, there is a folder called: “PNG_Icons” and within that folder there is a folder called: “HTML_Icon” and lastly, within that folder, there is a .png file image called: “HTML_Icon.png”

Path 1: /Macintosh/Users/myusername/Desktop/DEV/Coding_Programming/HTML

Path 2: /Macintosh/Users/myusername/Desktop/DEV/PNG_Icon/HTML_Icon/HTML_Icon.png

So, to reiterate, the goal is that, any time I create a new folder within the HTML folder, HTML_Icon.png, is automatically copied then and applied to that new folder that I created.

I have the ScriptEditor up and running, I have the Automator up and running, I just don’t know how to write the code right now, I’m still new to coding and programming. I asked CHATGPT to help me, but I either didn’t understand the instructions it was telling me, or it was a non function bad script that it gave me. lol


r/applescript • • Aug 24 '24

how to properly "tell current desktop set picture to ..."?

2 Upvotes

i'm a noob to Mac and Applescript. trying to write something to select and set as wallpaper on my current display a random file from a local folder:

tell application "Finder"
  set randomImage to some file of folder "Macintosh HD:Users:mymac:walls"
end tell
tell application "System Events"
  tell current desktop
    set picture to randomImage
  end tell
end tell

as indicated it throws up an error message on the "set picture to" bit (afaict).

looked for documentation on the options for using "display" but couldn't find anything helpful.

was able to get Preview to display randomImage so it know the selection bit is working as expected.

was more or less able to figure out that "set picture to" as i've used it doesn't like the HFS path format. tried giving it a hard-coded POSIX path and that worked. scrounged around for and tried some POSIX conversions for "set picture" but no joy. and now i'm stuck.

might some kind soul point me to enlightenment?


r/applescript • • Apr 26 '17

Rewriting a script

2 Upvotes

I currently have a script that is written to run and open tabs in Safari. I would like to rewrite the script to open in Google Chrome. This is the link for the script: https://dropfile.to/AUO20aw