Applescript – opening file inside app bundle

I have used Automator to create an app bundle that activates an app (“Fuse”) within the Resources directory of the bundle, which then opens the file “Exolon.tzx” (also located in Resources).

However, I can only get this to work when pointing to the full location of “Exolon.tzx” while the app is on my Desktop. Obviously, when I move the app it no longer works.

What do I need to change in this script to have it point to and open “Exolon.tzx” regardless of where I keep the app (in particular, I want it to work when I transfer the app to another Mac).

My script:

tell application "Fuse"         open POSIX file "/Users/almeath/Desktop/Exolon.app/Contents/Resources/Exolon.tzx"     end tell     tell application "System Events"         set frontmost of process "Fuse" to true     end tell     tell application "System Events"         keystroke "f" using command down     end tell 

Applescript time conversion between two format

I’m trying to calculate the time between a random date from today.

This work sometime , but the main issue I had, is my system date is DD/MM/YY and the date to compare to is US format MM/DD/YY

I used to convert my system date manually on the script using this

set today to short date string of (current date) set t to (time string of (current date)) set [_day, _month, _year] to [day, month, year] of date today --> {24, March, 2018}  set _month to _month * 1 --> 3 set _month to text -1 thru -2 of ("0" & _month) --> "03"  set the text item delimiters to "/" set today to {_month, _day, _year} as date --> "03/24/2018"  set [_month, _day, _year] to [day, month, year] of date today  set theNewestDate to today & " " & t as string 

But I getting some issue sometime.

Here is the script without the time convertor

set MyDate to short date string of (current date) set t to (time string of (current date)) set theNewestDate to MyDate & " " & t ## theNewsDate format "20/04/2019 12:40:57" / DD/MM/YY 24h  set theOldestDate to "04/20/2019 21:00:00" ## theOldestDateformat is MM/DD/YY   set myTimeAndDate1 to convertDate(theOldestDate) log result set theNewestDate to convertDate(theNewestDate) set difference to theNewestDate - myTimeAndDate1 log result log timeString(difference) ##return timeString(difference) ##log formatTime(difference) ##return formatTime set MyResult to timeString(difference)   # Convert date text to an AppleScript date. # format is DD/MM/YYYY hh:mm:ss (time is optional) to convertDate(dateText)     set dateTemplate to (current date)     ## tell dateTemplate to set {its day, its month, its year} to words 1 thru 3 of dateText     tell dateTemplate to set {its day, its month, its year} to words 1 thru 3 of dateText     set time of dateTemplate to 0     tell words of dateText to if (count it) > 3 then set time of dateTemplate to (hours * (item 4)) + (minutes * (item 5)) + (item 6)     return dateTemplate end convertDate  # Return an elapsed time string from a number of seconds. on timeString(theSeconds)     if class of theSeconds is integer then set theSeconds to "" & ¬         (theSeconds div days) & " days, " & ¬         (theSeconds mod days div hours) & " hours, " & ¬         (theSeconds mod hours div minutes) & " minutes, and " & ¬         (theSeconds mod minutes) & " seconds"     return theSeconds end timeString  # Return a formatted time string from a number of seconds. # format is hh:mm:ss (wraps at 24 hours) to formatTime(theSeconds)     if class of theSeconds is integer then tell "0" & ¬         (10000 * (theSeconds mod days div hours) ¬             + 100 * (theSeconds mod hours div minutes) ¬             + (theSeconds mod minutes)) ¬             to set theSeconds to (text -6 thru -5) & ":" & (text -4 thru -3) & ":" & (text -2 thru -1)     return theSeconds end formatTime 

Using AppleScript to delete an event still exists in Calendar

I’m trying to write a script that clears a calendar (an iCloud one) of all of its events. I have the following:

tell application "Calendar" tell calendar "Test calendar" set theEvents to every event repeat with current_event in theEvents delete current_event end repeat end tell end tell

In Script Debugger, I can see that the number of events in the list “theEvents” is going down as it deletes each one. If I run the script again, Script Debugger tells me that there are now no events in the calendar. However I can still access and change the events in the Calendar app, be that on the same computer or on another device or the iCloud website.

What’s going on here?

Cheers for any help,

Patrick

AppleScript : repeat with each item from end to beginning

I’m trying to do a repeat form a list but I would to repeat from the last item of the list to the newest instead of the another way.

How can I do that knowing that this will do in the wrong order :

   repeat with each from 2 to count of items of creationDate         --     end repeat 

What I’m trying to do is to return the item number of the latest item which content the text “whatever”

AppleScript basic date/time format and filename

I’m trying to wrap my head around AppleScript. I have a simple project to capture screenshots every several seconds and save them to a folder.

I found this helpful script on GitHub:

  • https://gist.github.com/jonobr1/a91c166a94a65e64c9b7

I’ve altered it a bit in an attempt to change the file name to this format:

screen_shot 2019-04-05 at 5.23.13 PM.jpg

Yet, I end up with a filename like this:

screen_shot0Thursday

I could use some help sorting out how to properly use the date and time functions within the script.

Here is the script:

set dFolder to "~/Desktop/screencapture/" set theDate to current date  do shell script ("mkdir -p " & dFolder)  set i to 0 repeat 960 times     do shell script ("screencapture " & dFolder & "screenshot_" & i & theDate & ".jpg")     delay 5 -- Wait for 5 seconds.     set i to i + 1 end repeat 

AppleScript to Add Multiple Files to VLC From List Results

I have a FileMaker Pro database of music files which uses AppleScript to pass it’s search results into an iTunes playlist.

I would like to use VLC instead of iTunes to play the audio files since I have a number of FLAC files which iTunes will not play.

I haven’t been able to figure out how to pass the AppleScript results to VLC. It’s easy to use AppleScript to get VLC to play a folder of music using:

tell application "VLC"     OpenURL "file:///Volumes/NoDoubt/Music/Rock Pop/PQR/Pink Floyd/Wish You Were Here/"     play end tell 

However, if I wanted to instead play a mix of songs from a variety of folders I need to be able to insert each file path into the VLC player.

This is what the AppleScript returned search results from FileMaker Pro looks like:

{"NoDoubt:Music:Rock Pop:ABC:The Beatles:Abbey Road:01_come_together_alac.m4a", "NoDoubt:Music:Rock Pop:DEF:Fleetwood Mac:Rumours:01_second_hand_news_alac.m4a", "NoDoubt:Music:Rock Pop:MNO:Van Morrison:hymns_to_the_silence_disc_1:1-02_i'm_not_feeling_it_anymore_alac.m4a", "NoDoubt:Music:Rock Pop:PQR:Pink Floyd:Wish You Were Here:04_wish_you_were_here_alac.m4a"} 

How can I pass the search results of these individual tracks to VLC to play?

applescript- script works when used in Script Editor but does nothing when saved as standalone app

Don’t judge, my first code lol. How do I fix the stated issue and suggestions for improvement would be great. I just tried making something to pause music when I started a video and start playing again when I pause or close it.

set str to "🔊" set playing to "playing" set paused to "paused" delay 1.1 tell application "iTunes"     set playerstate to (get player state) as text end tell tell application "Google Chrome"     get (count every tab of every window) as number     set ntabs to result end tell repeat until (ntabs = 0)     tell application "iTunes"         set playerstate to (get player state) as text     end tell     if playerstate is playing then         tell application "Google Chrome"             if title of front window contains str then set noisy to true             if not (title of front window contains str) then set noisy to false         end tell         if noisy = true then             tell application "iTunes" to pause             repeat until (noisy = false)                 tell application "Google Chrome"                     if not (title of front window contains str) then set noisy to false                 end tell             end repeat             tell application "iTunes" to play         end if     end if     tell application "Google Chrome"         get (count every tab of every window) as number         set ntabs to result     end tell end repeat quit application "MusicPause" 

AppleScript Get HTML of Chrome Active Tab

Is there a way to get the actual HTML of a current active tab in Chrome? Some websites use the position on the page to induce an AJAX call to expand the page further. So working with a URL only won’t cut it. Actually grabbing the current HTML is what I’m after.

At the moment, I can ask Chrome to open a new tab with the source of the tab, but that’s a bit cumbersome. The libraries haven’t shown me anything with regards to grabbing current active HTML.

Can I somehow use AppleScript to get the current active tab HTML?